Hello,
Is there a way to save for re-use the width of a tabular environment?
Tom
Graphics, Figures & Tables ⇒ Determine table width
NEW: TikZ book now 40% off at Amazon.com for a short time.

Determine table width
Hi Tom,
you can use a \hbox to "store" the tabular material; the width of that box will be the width of the tabular; the following example shows this approach:
P.S.: I've been really busy these days, but as soon as I can I will take a look at your question about footnotes.
you can use a \hbox to "store" the tabular material; the width of that box will be the width of the tabular; the following example shows this approach:
Code: Select all
\documentclass{article}
\begin{document}
% storing the tablular material in the box \box0
\setbox0=\hbox{%
\begin{tabular}{|ccc|}\hline
column1 & column2 & column3\\\hline
\end{tabular}}
% \wd0 stores the width of \box0 (i.e., the width of the tabular material)
\noindent\the\wd0
% just a test rule whose width will be equal to that of tha tabular
\noindent\rule{\the\wd0}{1pt}
% now we show the contents of \box0 (i.e., the tabular material)
\copy0
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: Determine table width
Thank you! I will try your code tomorrow.
Tom
Tom
Determine table width
Just a little comment: \copy0 won't empty the box register (\box0 in my example); you can use \box0 instead if you want to show the contents of the box register (the tabular material, in my example) and then to empty the box register:
Code: Select all
\documentclass{article}
\begin{document}
% storing the tablular material in the box register \box0
\setbox0=\hbox{%
\begin{tabular}{|ccc|}\hline
column1 & column2 & column3\\\hline
\end{tabular}}
% \wd0 holds the width of \box0 (i.e., the width of the tabular material)
\noindent\the\wd0
% just a test rule whose width will be equal to that of the tabular
\noindent\rule{\the\wd0}{1pt}
% now we show the contents of \box0 (i.e., the tabular material)
% without emptying \box0
\copy0
% \wd0 still has the same value since the box register is not empty
\noindent\the\wd0
% now we show the contents of \box0 (i.e., the tabular material)
% emptying \box0
\box0
% \wd0 is zero since the box register is now empty
\noindent\the\wd0
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: Determine table width
Hello,
You have a nice solution but, sadly, it will not work in my situation. I wish to use the code in Scientific WorkPlace (or Word). If the tabular environment is inside a command I cannot take advantage of the WorkPlace interface; I can place tabular commands inside another environment that is not inside a command. I should have been more specific about this but the problem did not occur to me until I tried to use your code.
Thanks for your efforts.
Tom
You have a nice solution but, sadly, it will not work in my situation. I wish to use the code in Scientific WorkPlace (or Word). If the tabular environment is inside a command I cannot take advantage of the WorkPlace interface; I can place tabular commands inside another environment that is not inside a command. I should have been more specific about this but the problem did not occur to me until I tried to use your code.
Thanks for your efforts.
Tom