3

I am trying to insert a table and left align it. The table has a caption, which of course, I want to be left-aligned. However, for some reason, the caption stays centered:

\documentclass{beamer}
\usetheme{Madrid}

\usepackage{graphicx, import}

\begin{document}

\begin{frame}{Table Analysis}
\begin{table}
    \raggedright
    \begin{tabular}{|c|c|}
        \hline 
        \textbf{Data}\\
        \hline
        1061.5 \\
        1384.7 \\
        1350.5 \\
        ...    \\
        1021.9 \\
        1097.3 \\
        1291.6 \\
        \hline
    \end{tabular}
\caption{Caption of Table.}
\end{table}
\end{frame}

\end{document}

I cannot change the \captionsetup , because I don't want all my captions in the presentation to be left-aligned. If, for example, the figure is centered, I want my caption to be centered as well. Only in this case, I want the table to be left-aligned.

1
  • 1
    Off-topic, but you do not need graphicx with beamer, as beamer already provides this functionality. Aug 24 '18 at 13:47
1

You could make use of caption package and use of the justification and singlelinecheck options as given in this answer. Also, in \captionsetup you could select the table option explicitly.

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{caption}
\usepackage{graphicx, import}
\captionsetup[table]{justification=raggedright,singlelinecheck=false}
\begin{document}

\begin{frame}{Table Analysis}
\begin{table}
    \raggedright
    \begin{tabular}{|c|c|}
        \hline 
        \textbf{Data}\\
        \hline
        1061.5 \\
        1384.7 \\
        1350.5 \\
        ...    \\
        1021.9 \\
        1097.3 \\
        1291.6 \\
        \hline
    \end{tabular}
\caption{Caption of Table.}
\end{table}
\end{frame}

\begin{frame}{Center figure}
\begin{figure}
    \centering
    \includegraphics[scale=0.5]{example-image-a}
    \caption{Center figure}
\end{figure}
\end{frame}

\end{document}

to get

enter image description here

enter image description here

1

In beamer the table environment does little more than centering the table. So if you don't want to centre the table, simply don't put it in a table environment.

If you like the caption to look the same you can either manually write "Table: " (as in my answer) or use the \captionof macro from the caption package (which is explained in the answer by Raaja)

\documentclass{beamer}
\usetheme{Madrid}

\usepackage{
%graphicx, 
import}

\begin{document}

\begin{frame}{Table Analysis}
%\begin{table}
%    \raggedright
    \begin{tabular}{|c|c|}
        \hline 
        \textbf{Data}\\
        \hline
        1061.5 \\
        1384.7 \\
        1350.5 \\
        ...    \\
        1021.9 \\
        1097.3 \\
        1291.6 \\
        \hline
    \end{tabular}

{\usebeamercolor*[fg]{caption name}Table:} Caption of Table.
%\end{table}
\end{frame}

\end{document}

And just for completeness because you say that you cannot use \captionsetup:

If you use it within a group it won't affect other tables or figures

{
\captionsetup[table]{justification=raggedright,singlelinecheck=false}
\begin{table}
\caption{Caption of Table.}
\end{table}
}

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.