0

I have the following simplified document ():

\documentclass[10pt]{book}
\usepackage{float}
\let\origfigure\figure
\let\endorigfigure\endfigure
\renewenvironment{figure}[1][2] {
    \expandafter\origfigure\expandafter[H]
} {
    \endorigfigure
}
\usepackage{subfig}
\usepackage{graphicx}

\begin{document}%

\begin{table}[ht]
\subfloat[]{\scalebox{1.5}{\input{./ta}}}\quad
\subfloat[]{\scalebox{1.5}{\input{./tb}}}
\caption{Caption about here}
\end{table}

\end{document}

It refers to two simple tables ta.tex and tb.tex they are as follows:

% latex table generated in R 3.5.2 by xtable 1.8-3 package
% Thu Jan 17 09:17:38 2019
\begin{tabular}{rl}
  \hline
 & Other Debriefs \\ 
  \hline
1 & nothing here \\ 
   \hline
1 & nothing here \\ 
   \hline
1 & nothing here \\ 
   \hline
1 & nothing here \\ 
   \hline
\end{tabular}

and

\begin{tabular}{rl}
  \hline
 & Other Reviews \\ 
  \hline
1 & Every week \\ 
  2 & nada \\ 
   \hline
\end{tabular}

Because the tables contain unequal number of rows they are not top - aligned. Instead they are vertically centered side by side. Can the above code be modified so that the 2 tables are vertically top-aligned? I found a solution where floatrow package - but unfortunately it conflicts with float - which I need for the images to be placed where they should be (I am working in R markdown, I am very inexperienced with Latex). Essentially this would be a modification to Marcin Kosiński's solution Side by side Xtables in Rmarkdown

migrated from stackoverflow.com Jan 17 at 20:09

This question came from our site for professional and enthusiast programmers.

  • 1
    Thank you, this has worked. If I ask the same question on tex forum - will it be against the rules? – r0berts Jan 17 at 15:36
  • Cross-posting is often discouraged, so be careful. Occasionally somebody will come up rather strongly in a comment on one or both, so I suggest against it. Since you accepted the answer below, if you have further related problems, I recommend you make the next question add sufficient purpose, and consider which site is best and post there. In this case, since nothing about it is in R, perhaps the other site would work well (better?). – r2evans Jan 17 at 15:48
1

This is a bit of a hack perhaps, but it is the way I usually work. I make my layout good enough and then go back at the end and do hard tweaks like this to make it ready for publication. Essentially, you are putting your table objects in minipage containers to isolate them and then subtracting a little space before the second one to force it up:

\begin{table}[ht]
  \begin{minipage}{0.5\textwidth}
    \subfloat[]{\scalebox{1.5}{\input{./ta}}}\quad
  \end{minipage}
  \begin{minipage}{0.5\textwidth}
    \vspace*{-13mm}
    \subfloat[]{\scalebox{1.5}{\input{./tb}}}
    \end{minipage}
\caption{Caption about here}
\end{table}

enter image description here

  • Great, very useful, I will make note of this. I temporarily solved this by making R replace via gsub in sub-tables the first line from \begin{tabular}{rl} to \begin{tabular}[t]{rl} - not fully sure why it works, but it does. – r0berts Jan 17 at 13:22
  • Right, that is a better solution, I missed you were using float without specifying the alignment. [t] is top aligned: (en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions) – trosendal Jan 17 at 13:30
  • How would you specify alignment at the document level then? – r0berts Jan 17 at 15:37
2

I would use the subcaption package:

\documentclass[10pt]{book}
\usepackage{float}
\usepackage{subcaption}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}%

\begin{table}[ht]
\centering
\begin{subtable}[t]{0.4\linewidth}
    \begin{tabular}[t]{rl}
  \hline
 & Other Debriefs \\
  \hline
1 & nothing here \\
1 & nothing here \\
1 & nothing here \\
1 & nothing here \\
   \hline
\end{tabular}
    \caption{}\label{tab:a}
\end{subtable}
\hfil
\begin{subtable}[t]{0.4\linewidth}
\begin{tabular}[t]{rl}
  \hline
 & Other Reviews    \\
  \hline
1 & Every week      \\
2 & nada            \\
   \hline
\end{tabular}
    \caption{}\label{tab:b}
\end{subtable}
    \caption{Caption about here}
    \label{tab:ab}
\end{table}

\end{document}

enter image description here

(red lines indicate a page layout)

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.