2

I wanted to put the caption of a table to its left, so I tried taking the approach suggested in this answer. As pointed out in the only comment to there, I had a misalignment issue as well. The comment says that adding \mbox{}\\[-\baselineskip] immediately inside each minipage solved the problem because it produced a dummy line from which the alignments could hang.

Here is exactly what I have in my .tex file:

\begin{table}[!t]
\begin{minipage}[t]{0.25\textwidth}
  %\mbox{}\\[-\baselineskip]
  \caption{The two ``super''-relations and their constituent fine-grained UMLS types.}
  \label{tab:super-rels}
\end{minipage}
\hfill
\begin{minipage}[t]{0.73\textwidth}
%\mbox{}\\[-\baselineskip]
  \centering
  \frame{
    \begin{tabular}[t]{l l}
      \texttt{beneficial} (\textsc{b}) & {\small may\_treat, may\_prevent, treats, prevents}             \\[5pt]
      \texttt{harmful} (\textsc{h})    & {\small cause\_of, causative\_agent\_of, contraindicated\_drug} \\
    \end{tabular}
  }
\end{minipage}
\end{table}

But what it produces is a far cry from what I want: misaligned minipage problem

What I want is that the top horizontal line of the frame in the right minipage should align with the top text line of the caption in the left minipage.

Note: Uncommenting the \mbox{}\\[-\baselineskip] lines has absolutely no effect on the final pdf output.

Additional information (potentially relevant portions from the preamble):

\documentclass[11pt,oneside]{book}
%% preamble based on http://www.khirevich.com/latex %%
\usepackage[DIV=14,BCOR=2mm,headinclude=true,footinclude=false]{typearea}
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[activate={true,           % activate protrusion
                  nocompatibility % activate expansion
                 },
        final,                    % enable microtype (disable: "draft")
        tracking=true,            % activate tracking
        kerning=true,             % activate kerning
        spacing=true,             % activate spacing
        factor=1100,              % add 10% to protrusion (default: 1000)
        stretch=10,shrink=10]     % reduce streching/shrinking (default: 20/20)
        {microtype}
\microtypecontext{spacing=nonfrench}
\usepackage[automark,headsepline,nouppercase]{scrpage2}
\usepackage{wrapfig}

\pagestyle{scrheadings}
5
  • So far, you've only told us that what you have so far is not what you want. Please tell us what do want, and please be specific.
    – Mico
    Sep 17, 2015 at 21:13
  • Thanks for pointing that out! I have added the desired behavior in the question, just after the picture. Sep 17, 2015 at 21:25
  • Could you also tell us which document class you use and how wide the text block is (or, alternatively, the page width and the margins)?
    – Mico
    Sep 17, 2015 at 21:29
  • Added potentially relevant portions from my preamble. I am not explicitly setting the margins, though. Sep 17, 2015 at 21:39
  • The top of a minipage is actually the baseline of the first line. \frame puts the baseline at the bottom of the rectangle. Sep 17, 2015 at 21:41

2 Answers 2

1

\raisebox{-\height}{whatever} moves the baseline to the very top of {whatever}. Evidently setting \abovecaptionskip=0pt also aligns the caption to the very top.

\documentclass{article}

\begin{document}
\begin{table}[!t]
\begin{minipage}[t]{0.25\textwidth}
  \abovecaptionskip=0pt
  \caption{The two ``super''-relations and their constituent fine-grained UMLS types.}
  \label{tab:super-rels}
\end{minipage}
\hfill
\begin{minipage}[t]{0.73\textwidth}
%\mbox{}\\[-\baselineskip]
  \centering
  \raisebox{-\height}{\frame{
    \begin{tabular}[t]{l l}
      \texttt{beneficial} (\textsc{b}) & {\small may\_treat, may\_prevent, treats, prevents}             \\[5pt]
      \texttt{harmful} (\textsc{h})    & {\small cause\_of, causative\_agent\_of, contraindicated\_drug} \\
    \end{tabular}
  }}
\end{minipage}
\end{table}
\end{document}

side caption

2
  • Nice! Could you please add an explanation for the \raisebox{-\height} part? Sep 17, 2015 at 21:53
  • Please use ragged text for the caption. The inter-word spacing with the current settings look awful. Sep 17, 2015 at 23:47
2

enter image description here

\documentclass[11pt,oneside]{book}
\usepackage[DIV=14,BCOR=2mm,headinclude=true,footinclude=false]{typearea}
\usepackage[T1]{fontenc}
\usepackage{charter,tabularx}
\usepackage[activate={true,       % activate protrusion
        nocompatibility},         % activate expansion                 
        final,                    % enable microtype (disable: "draft")
        tracking=true,            % activate tracking
        kerning=true,             % activate kerning
        spacing=true,             % activate spacing
        factor=1100,              % add 10% to protrusion (default: 1000)
        stretch=10,shrink=10]     % reduce streching/shrinking (default: 20/20)
        {microtype}
\begin{document}

\begin{table}\centering
\begin{tabularx}{0.28\textwidth}[t]{X} 
\abovecaptionskip=0pt
\caption{The two ``super''-relations and their constituent fine-grained UMLS types.}
\label{tab:super-rels}
\end{tabularx}
\hfill
\begin{tabularx}{0.7\textwidth}[t]{|lX|} \hline
\texttt{beneficial} (\textsc{b}) & {\small may\_treat, may\_prevent, treats, prevents}             \\[5pt]
\texttt{harmful} (\textsc{h})    & {\small cause\_of, causative\_agent\_of, contraindicated\_drug} \\ \hline
\end{tabularx}
\end{table}

\end{document}

Two tabularxes could do the same thing as minipages because they have an optional positioning argument (t,b,c default). But the main problem here is that a \caption is not like the normal text because it has an \abovecaptionskip which is not zero by default.

First, we set \abovecaptionskip=0pt, then use the [t] positioning option for both tabularxes to keep the two tops aligned.

1
  • +1, but could you also please add an explanation of why this works? Sep 17, 2015 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .