Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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).

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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