Graphics, Figures & TablesCentering caption in \minipage

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
i.mehrzad
Posts: 4
Joined: Sun Jul 05, 2009 5:23 am

Centering caption in \minipage

Post by i.mehrzad »

I have looked all over the net for this. I have two tables side by side and have done this using the minipage argument. The problem is that the caption for the tables are not center aligned. Reference http://texblog.wordpress.com/2007/08/01 ... -minipage/

Can someone help me with centering the caption of each of the tables.

Thanking you,
Mehrzad

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

fatra2
Posts: 126
Joined: Fri May 01, 2009 1:43 pm

Centering caption in \minipage

Post by fatra2 »

Hi there,

Have you tried switching the order of the environment. Meaning,

Code: Select all

\begin{minipage}[b]{0.5\linewidth}
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|c|}
\hline
1&1&1\\
\hline
2&2&2\\
\hline
\end{tabular}
\end{table}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.5\linewidth}
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|c|}
\hline
1&1&1\\
\hline
2&2&2\\
\hline
\end{tabular}
\end{table}
\end{minipage}
I just find it very peculiar to enter a minipage environment inside a table. Intuitively, I would create a minipage and then create a table.

Cheers
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Centering caption in \minipage

Post by localghost »

fatra2 wrote:[...] I just find it very peculiar to enter a minipage environment inside a table. [...]
There's nothing unusual in this method. Some well known packages internally exactly proceed this way.
i.mehrzad wrote:I have looked all over the net for this. I have two tables side by side and have done this using the minipage argument. The problem is that the caption for the tables are not center aligned. [...]
I can't see the problem. The method of your reference works fine.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs}


\begin{document}
  \begin{table}[!ht]
    \begin{minipage}[t]{0.5\linewidth}
      \caption{default}\label{tab:table1}
      \centering
      \begin{tabular}{cc}\toprule
        Table head & Table head \\ \midrule
        Some values & Some values \\
        Some values & Some values \\
        Some values & Some values \\ \bottomrule
      \end{tabular}
    \end{minipage}
    \hspace{0.5cm}
    \begin{minipage}[t]{0.5\linewidth}
      \caption{default}\label{fig:table2}
      \centering
      \begin{tabular}{cc}\toprule
        Table head & Table head \\ \midrule
        Some values & Some values \\
        Some values & Some values \\
        Some values & Some values \\ \bottomrule
      \end{tabular}
    \end{minipage}
  \end{table}
\end{document}
Centered single line captions are the default behaviour. Build a minimal working example (MWE) that shows the opposite.


Best regards
Thorsten
Post Reply