I have a python script that spits out files that are subsequently read in by latex to compile a report. At times, user text labels are long and risk breaking my latex tables.
I'm using the following to limit table cell width:
\newcolumntype{M}{>{\begin{varwidth}{0.3\textwidth}}c<{\end{varwidth}}}
However, now long text spills onto a second (or third...) line which makes my table grow. The table still looks good, but I'd like to prevent it from growing so that the table size is consistent.
I tried \noindent\begin{minipage}[t][2.5cm][t]{\textwidth} ... \end{minipage} but that didn't seem to work.
I'd prefer to shrink the typeface to make it fit. Alternately, I'd accept truncation.
MWE:
\documentclass{article}
\usepackage{array}
\usepackage{varwidth} %for the varwidth minipage environment
\begin{document}
\newcolumntype{M}{>{\begin{varwidth}{0.3\textwidth}}c<{\end{varwidth}}} %M is for Maximal column
\begin{tabular}{rrrrrrrr}
\multicolumn{2}{M} {This is sometimes long} & & \multicolumn{2}{M}{This is also sometimes long but I don't want the table to grow with it} & & \multicolumn{2}{M}{and this can be long} \\
key & value & & key & value & & key & value \\
0 & 1 & & 0 & 1 & & 0 & 1\\
\end{tabular}
\end{document}
p{0.3\textwidth}
as column type? Do I get it right, that the cell should automatically shrink the text (or truncate it) if it is longer than, say, two lines?p{0.3\textwidth}
would largely do the same as mynewcolumntype
scheme. Both restrict the cell from growing too far horizontally (or, with p{}, changing horizontal shape at all). I want to prevent vertical growth beyond, say, 2 lines.