[Tex/LaTex] How to manipulate width and position of items inside floatrow

floatrowfloatshorizontal alignment

From this answer by @lockstep I learned, how to put figure and table side by side:

\documentclass{article}

\usepackage{floatrow}
% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\begin{document}

\begin{figure}
\begin{floatrow}
%tried \ffigbox[0.5\linewidth]{%
\ffigbox{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}
\capbtabbox{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}
}{%
  \caption{A table}%
}
\end{floatrow}
\end{figure}

\end{document}

enter image description here

I don't understand, how to set the width of every column and align the table/figure left, center, right.

In the docs I found, that \ffigbox has width parameter and tried 0.5\linewidth, making each column half of the page. But that's all I achieved so far.

Best Answer

Perhaps the best way to illustrate how the different commands work is to use some auxiliary boxes:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{xcolor}
\usepackage{floatrow}

\newcommand\MyBox[2][red!70!black]{{%
  \setlength\fboxsep{0pt}\fcolorbox{#1}{white}{#2}}}

\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\pagestyle{empty}

\begin{document}

\begin{figure}
\MyBox[blue]{\begin{floatrow}
\MyBox{\ffigbox[\FBwidth]{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}}%
\MyBox{\capbtabbox[\FBwidth]{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}%
}{%
  \caption{A table}%
}}
\end{floatrow}}
\end{figure}

\begin{figure}
\MyBox[blue]{\begin{floatrow}
\MyBox{\ffigbox[8cm]{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}}%
\MyBox{\capbtabbox[7cm]{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}%
}{%
  \caption{A table}%
}}
\end{floatrow}}
\end{figure}

\begin{figure}
\MyBox[blue]{\begin{floatrow}
\MyBox{\ffigbox[8cm]{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}}\qquad%
\MyBox{\capbtabbox[7cm]{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}%
}{%
  \caption{A table}%
}}
\end{floatrow}}
\end{figure}

\end{document}

enter image description here

The floatrow environment (with default settings) reserves a box having a width equal to the entire \textwidth (the blue boxes in the example); the content will be centered by default.

The optional argument for ffigbox and captabbox allows to specify the width to be used for the content of each of these commands (the red boxes in the example); \FBwidth will give you the natural width (see first example), but you can select any other values (second and third example). In the third example a \qquad space was further introduced between the image and the table.

To control the position of the object inside its box, the package offers the objectset key which admits values similiar to those of justification for \captionsetup from the caption package; a little example using objectset=raggedright and the same settings for the width as as in the second example from the code above:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{xcolor}
\usepackage{floatrow}

\newcommand\MyBox[2][red!70!black]{{%
  \setlength\fboxsep{0pt}\fcolorbox{#1}{white}{#2}}}

\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\pagestyle{empty}

\begin{document}


\thisfloatsetup{objectset=raggedright}
\begin{figure}
\MyBox[blue]{\begin{floatrow}
\MyBox{\ffigbox[8cm]{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}}\qquad%
\MyBox{\capbtabbox[7cm]{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}%
}{%
  \caption{A table}%
}}
\end{floatrow}}
\end{figure}

\end{document}

enter image description here

And, of course, you can use all the power of floatrow with all the power of caption to have, for example, both objects and captions raggedright or raggedleft:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{xcolor}
\usepackage[singlelinecheck=off,justification=raggedright]{caption}
\usepackage{floatrow}

\newcommand\MyBox[2][red!70!black]{{%
  \setlength\fboxsep{0pt}\fcolorbox{#1}{white}{#2}}}

\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\pagestyle{empty}

\begin{document}

\thisfloatsetup{objectset=raggedright}
\begin{figure}
\MyBox[blue]{\begin{floatrow}
\MyBox{\ffigbox[8cm]{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}}\qquad%
\MyBox{\capbtabbox[7cm]{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}%
}{%
  \caption{A table}%
}}
\end{floatrow}}
\end{figure}

\thisfloatsetup{objectset=raggedleft}
\captionsetup{singlelinecheck=off,justification=raggedleft}
\begin{figure}
\MyBox[blue]{\begin{floatrow}
\MyBox{\ffigbox[8cm]{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}}\qquad%
\MyBox{\capbtabbox[7cm]{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}%
}{%
  \caption{A table}%
}}
\end{floatrow}}
\end{figure}

\end{document}

enter image description here