1

I have a table that contains the word "bar" in column 1, and a picture of a drink in column 2. The picture is offset a little vertically, so I want to bring it down a bit. So, I used the raisebox command, but it gives the following error:

Undefined control sequence. ... Bar & \raisebox{\0.2cm}\includegraphics

Otherwise the code works fine. So, which package do I install for resolving this issue? I thought it should be under graphicx. I also tried graphicx, but to no avail. And I also searched online for which package to install to get raisebox to work, but I found no relevant solution.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{tabular}{|c|c|}
            \hline \rule[-2ex]{0pt}{5.5ex}  \bf Locale & \bf Index  \\ 
            \hline \rule[-2ex]{0pt}{5.5ex}  Bar & \raisebox{\-0.2cm}\includegraphics[]{index_bar.png} \\ 
            \hline 
\end{tabular}     
\end{document}

The output below is shown when I remove the raisebox:

enter image description here

  • 1
    \raisebox is a LaTeX command. You have the error \0.2cm, that's the error. It should read 0.2cm – user31729 Jun 14 '17 at 7:21
  • 1
    There are braces missing. And the backslash before the 0 is wrong. \raisebox{0.2cm}{\includegraphics[]{index_bar.png}}. – Ulrike Fischer Jun 14 '17 at 7:21
  • @ChristianHupfer I also tried \raisebox{\totalheight}. The error is still the same: unrecognized command raisebox. Do you have a solution? – Kristada673 Jun 14 '17 at 7:22
  • 2
    Your \raisebox should raise something. And this something is in this case your image. So the (complete) image should be in the second argument of the raisebox command. – Ulrike Fischer Jun 14 '17 at 7:26
  • 1
    Could you please stop to use this backslashes before numbers? It doesn't matter if it perhaps works somehow. It is wrong syntax. Fix lengths are used without backslashes. E.g. {0.2cm} or {5mm} or {-3cm}. Which value is best, depends on your image that we don't have. – Ulrike Fischer Jun 14 '17 at 7:59
3

I suppose, that you like to obtain something like this:

enter image description here

Solution below doesn't solve your issue with \raisebox (comments above solve this problem) but rather avoiding them with simple not use it. Instead it are employed packages adjustbox (for vertical centering image in cell) and makecell (for adding vertical gaps around cells' contents):

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}                  % added
\usepackage{makecell}                           % added
\renewcommand\theadfont{\normalsize\bfseries}   % added (from makecell)

\begin{document}
\begin{center}
    \setcellgapes{\tabcolsep}                   % added (from makecell)
    \makegapedcells                             % added (from makecell)
\begin{tabular}{|c|c|}
            \hline 
\thead{Locale} & \thead{Index}  \\              % changed
            \hline 
Bar & \includegraphics[width=11mm, height=11mm, % determine size of demo imege
                       valign=m]                % added (from adjustbox)
                       {index_bar.png} \\
            \hline
\end{tabular}
\end{center}
\end{document}

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.