2

A coworker and I are working on templates for documentation in which certain types of tables are a repeated element. These tables vary in content depth, often wrapping the content in Column B of the MWE.

Because these elements repeat, we've set a consistent width for them. However, some are very short, widthwise, and do not stretch to meet the minimum width. The MWE shows this:

\documentclass{article}
\usepackage[margin=0.25in]{geometry}
\usepackage{mwe}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage{tabulary}

\begin{document}

\begin{table}[h]
\centering
\begin{tabulary}{0.66\textwidth}{lL}
\toprule
\multicolumn{2}{l}{Example A} \\
\midrule
\multicolumn{2}{c}{\includegraphics[scale=0.5]{example-image-a}} \\
\midrule
Column A & Column B \\
\midrule
Label I & A very little bit of text.\\
\bottomrule
\end{tabulary}
\caption{Example A}
\end{table}

\begin{table}[h]
\centering
\begin{tabulary}{0.66\textwidth}{lL}
\toprule
\multicolumn{2}{l}{Example B} \\
\midrule
\multicolumn{2}{c}{\includegraphics[scale=0.5]{example-image-b}} \\
\midrule
Column A & Column B \\
\midrule
Label I & \blindtext\\
\bottomrule
\end{tabulary}
\caption{Example B}
\end{table}

\end{document}

Adding the following hack to Example A forces the desired width, but seems like a terrible solution: Label I & A very little bit of text.\hspace*{50em}\\

Certainly there is a better way to do this?

Update

This question regarding a similar scenario presented a patch and some helpful history regarding tabulary.

However, something (perhaps the images?) involved here breaks the patch suggested there, resulting in an arithmetic overflow. Manual intervention to use tabularx in underfull tables is reasonable, but not a scenario that will support automation.

Is there a way to provide arithmetic for the patch from the \includegraphics calls, or is this simply pushing too far into unreasonable territory?

  • 1
    Are you sure you don't want tabularx, instead? – egreg May 13 '15 at 6:26
2

with tabularx you can fix the whole table width and X columns adjust their size independently from their contents.

\documentclass{article}
\usepackage[margin=0.25in]{geometry}
\usepackage{mwe}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage{tabulary}
\usepackage{tabularx}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}

\begin{document}

%\blindtext

\begin{table}[h]
\centering
\begin{tabularx}{.66\textwidth}{lY}
\toprule
\multicolumn{2}{l}{Example A} \\
\midrule
\multicolumn{2}{c}{\includegraphics[scale=0.5]{example-image-a}} \\
\midrule
Column A & Column B \\
\midrule
Label I & A very little bit of text\\
\bottomrule
\end{tabularx}
\caption{Example A}
\end{table}

\begin{table}[h]
\centering
\begin{tabulary}{0.66\textwidth}{lL}
\toprule
\multicolumn{2}{l}{Example B} \\
\midrule
\multicolumn{2}{c}{\includegraphics[scale=0.5]{example-image-b}} \\
\midrule
Column A & Column B \\
\midrule
Label I & \blindtext\\
\bottomrule
\end{tabulary}
\caption{Example B}
\end{table}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.