From: wolf Date: Fri, 14 Sep 2001 16:52:35 +0000 (+0000) Subject: Better formatting of tables: columns are now as wide as the widest X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ac9119adf0faa182445b81ac1f51401c1526e0b;p=dealii-svn.git Better formatting of tables: columns are now as wide as the widest entry, headers are centered over column. git-svn-id: https://svn.dealii.org/trunk@5014 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/source/table_handler.cc b/deal.II/base/source/table_handler.cc index c9d239a54f..03f7d8086c 100644 --- a/deal.II/base/source/table_handler.cc +++ b/deal.II/base/source/table_handler.cc @@ -14,6 +14,7 @@ #include +#include #include #include @@ -211,61 +212,84 @@ void TableHandler::write_text(std::ostream &out) const std::vector sel_columns; get_selected_columns(sel_columns); + const unsigned int nrows = n_rows(); + const unsigned int n_cols = sel_columns.size(); -// write the caption line + // first compute the widths of each + // entry of the table, in order to + // have a nicer alignement + std::vector > + entry_widths (nrows, std::vector(n_cols)); + for (unsigned int i=0; i::const_iterator + col_iter=columns.find(key); + Assert(col_iter!=columns.end(), ExcInternalError()); + + const Column & column = col_iter->second; + + // write it into a dummy + // stream, just to get its + // size upon output + std::ostringstream dummy_out; + dummy_out << std::setprecision(column.precision); + + if (col_iter->second.scientific) + dummy_out.setf (std::ios::scientific, std::ios::floatfield); + else + dummy_out.setf (std::ios::fixed, std::ios::floatfield); + column.entries[i]->write_text (dummy_out); + dummy_out << std::ends; + + // get size, note that we are + // not interested in the + // trailing \0 + entry_widths[i][j] = dummy_out.str().length()-1; + }; + + // next compute the width each row + // has to have to suit all entries + std::vector column_widths (n_cols, 0); + for (unsigned int i=0; i >::const_iterator - super_iter=supercolumns.find(key); - - - if (super_iter!=supercolumns.end()) // if supercolumn - { - std::vector::const_iterator col_key=super_iter->second.begin(); - for (;col_key!=super_iter->second.end(); ++col_key) - { - const std::map::const_iterator - col_iter=columns.find(*col_key); - if (col_iter->second.scientific && - col_iter->second.precision>1) - column_string_size+=16; - else - column_string_size+=8; - } - } - else - { - const std::map::const_iterator - col_iter=columns.find(key); - if (col_iter->second.scientific && - col_iter->second.precision>1) - column_string_size=16; - else - column_string_size=8; - } - column_string_size-=1; - - if (key.size()>column_string_size) - key.erase(column_string_size); + const std::string & key = column_order[j]; - out.setf(std::ios::left); - out << std::setw(column_string_size) - << key << "\t"; + // if the key of this column is + // wider than the widest entry, + // then adjust + if (key.length() > column_widths[j]) + column_widths[j] = key.length(); + + // now write key. try to center + // it somehow + const unsigned int front_padding = (column_widths[j]-key.length())/2, + rear_padding = (column_widths[j]-key.length()) - + front_padding; + for (unsigned int i=0; i::const_iterator col_iter=columns.find(key); Assert(col_iter!=columns.end(), ExcInternalError()); @@ -278,10 +302,9 @@ void TableHandler::write_text(std::ostream &out) const out.setf(std::ios::scientific, std::ios::floatfield); else out.setf(std::ios::fixed, std::ios::floatfield); - column.entries[i]->write_tex(out); - - if (jwrite_text(out); + out << " "; } out << std::endl; }