3

Is there some way of getting the current column width in a tabu table in the same way that one can refer to \columnwidth in a multicol?

For example, the following gallery works but its a bit ugly since the column content had to know its width. i.e. we had to specify [width=.45\textwidth] whereas we would prefer not to have to do that. If this were a multicol then we could have just used [width=\columnwidth] in its place.

I searched through the tabu documentation looking for all occurrences of width but did not find it.

\documentclass{article}
\usepackage{graphicx}
\usepackage{tabu}

\begin{document}

\begin{tabu}{XX}
\framebox{\includegraphics[width=.45\textwidth]{myfig}} &
\framebox{\includegraphics[width=.45\textwidth]{myfig}} \\
Some text.  & Some more Text.  \\
\end{tabu}

\end{document}
3

I don't know if it's documented, but you can always refer to the current width of a parbox by \linewidth:

\documentclass{article}
\usepackage{graphicx}
\usepackage{tabu}

\begin{document}

\begin{tabu}{XX}
\framebox{\includegraphics[width=\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax]{myfig}} &
\framebox{\includegraphics[width=\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax]{myfig}} \\
Some text.  & Some more Text.  \\
\end{tabu}

\end{document}

Just say \linewidth instead of the complicated \dimexpr...\relax if you don't want the frame.

Of course the \linewidth would change in a nested list based environment; in this case you can always use \hsize (this is surely undocumented).

  • Thanks. Accepted. I don't understand the part about not wanting the frame. Both \framebox{\includegraphics[width=\linewidth]{myfig}} and \includegraphics[width=\linewidth]{myfig} seem to work. – user1189687 Jul 13 '12 at 11:03
  • @user1189687 The first will give an "Overfull \hbox" message because of the padding around the figure to leave space for the frame. – egreg Jul 13 '12 at 11:09

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.