Using commands within tabular definition result in error ! Missing $ inserted. In this case, it is the \, that causes problems when calling the custom command. Same commands work fine outside tabular definition, so how do I use commands in the parameter?
MWE:
\documentclass{article}
\usepackage{calc}
\usepackage{array}
\newcommand{\comtest}[1]{
\begin{tabular}{p{\widthof{#1}}}
#1
\end{tabular}
}
\begin{document}
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\fbox{\comtest{Text\,}}
\end{document}
EDIT: I need to use the width measurement for the paragraph width within the tabular so I can specify to vertically center multiple cells. Below is a less-contrived example. Padding modifiers removed for brevity.
\documentclass{article}
\usepackage{calc}
\usepackage{array}
%produces an image and following text vertically centered
% [image command, image width, text]
\newcommand{\vcenteredimagetext}[3]{{
\begin{tabular}{@{}>{\centering}m{#2}@{}@{\ }>{\centering\arraybackslash}m{\widthof{#3}}@{}}
#1\\
\end{tabular}
}}
\begin{document}
\vcenteredimagetext{\rule{0.5in}{0.5in}}{0.5in}{\bf{Text}}
\bf{Text}
\end{document}
EDIT #2:
Decided to go with \raisebox option here instead of pursuing fixes to this method further.
ccolumn would be sufficient. – egreg Aug 21 '13 at 15:35\bfhas been deprecated sine latex2e was released, but if you do use it its syntax is{\bf Text}not\bf{Text}The whole construction is weird, if you want to vertically centre something, you could use a tabular, or more directly use\raisebox{-.5\height}{Text}– David Carlisle Aug 21 '13 at 17:14\raiseboxcommand I suggest above does that, there is no need for a table at all. – David Carlisle Aug 21 '13 at 20:41\raiseboxmight work after all if I can get a few things worked out. New question posted here.Make a response recommending
– TomH57 Aug 21 '13 at 20:55\raiseboxand I'll mark it as the answer if I can get the lengths figured out. Thanks!