5

How do I write the table width in the log file? Say, for instance, that I have 2 tables -- when I compile the tex file, I want to write the width/breadth in the log file. Is that possible through a macro or definition, because I need to use this in my own template, rather than in a file

\documentclass[twocolumn]{article}
\usepackage{showframe}

\begin{document}

\begin{table}[ht]
\caption{Nonlinear Model Results}
\begin{tabular}{c c c c}
\hline
Case & Method
\#1 & Method
\#2 & Method
\#3\\
\hline
1 & 50 & Sample Piece & 970\\
2 & 47 & Sample Piece & 230\\
\hline
\end{tabular}
\end{table}

\begin{table}[ht]
\caption{Nonlinear Model Results}
\begin{tabular}{c c c c}
\hline
Case & Method
\#1 & Method
\#2 & Method
\#3\\
\hline
1 & 50 & Sample Piecedgjgh aweg & 970\\
2 & 47 & Sample Piece & 230\\
\hline
\end{tabular}
\end{table}


\end{document}
  • Do you want to save the dimensions of the tabular environments or those of the table environments? – Mico Mar 16 '17 at 10:28
  • @Mico Actually i need to get the tabular environment – user52124 Mar 16 '17 at 10:48
6

This cannot measure the caption width...only the tabular width. It works by placing the tabular in a temporary box, and using \typeout to print the width into the log file.

EDITED to place this in its own environment, mtabular (measure tabular). Additionally, mtabular now has an optional argument, to use as the ID, if the default use of \thetable is not appropriate (depending on usage).

\documentclass[twocolumn]{article}
\usepackage{showframe,environ}
\newenvironment{mtabular}[2][\thetable]{%
  \gdef\savemtabopt{#1}%
  \setbox0=\hbox\bgroup\begin{tabular}{#2}}{\end{tabular}\egroup\copy0
  \typeout{Table \savemtabopt. width is \the\wd0.}%
}
\begin{document}

\begin{table}[ht]
\caption{Nonlinear Model Results}
\begin{mtabular}{c c c c}
\hline
Case & Method
\#1 & Method
\#2 & Method
\#3\\
\hline
1 & 50 & Sample Piece & 970\\
2 & 47 & Sample Piece & 230\\
\hline
\end{mtabular}%
\end{table}

\begin{table}[ht]
\caption{Nonlinear Model Results}
\begin{mtabular}{c c c c}
\hline
Case & Method
\#1 & Method
\#2 & Method
\#3\\
\hline
1 & 50 & Sample Piecedgjgh aweg & 970\\
2 & 47 & Sample Piece & 230\\
\hline
\end{mtabular}
\end{table}


\end{document}

enter image description here

enter image description here

  • Thanks for your reply, is that possible through a macro or definition, because i need to use this in my own Teamplate, rather than file – user52124 Mar 16 '17 at 10:37
  • @user52124 Please see my revised answer, introducing the mtabular environment. – Steven B. Segletes Mar 16 '17 at 11:01

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.