7

I have the following table (using booktabs):

\begin{table}
\caption{Table}
\centering
\begin{tabular}{ccccc}
\toprule
& \multicolumn{4}{c}{Lags}\\[\defaultaddspace]
 & 5 & 10 & 15  & 20 \\[\defaultaddspace]
 EUR/USD &  &  &  &  \\[\defaultaddspace]
 Ljung-Box-Test & 0,4936 & 0,7841 & 0,8457 & 0,8822 \\
\bottomrule
\end{tabular}
\end{table}

which results in the following table:

Result of above code

I would like to establish some hierarchy by indenting the "Ljung-Box-Test" text within the first column (I will be adding more currency pairs / categories below).

Any help would be much appreciated!

Thanks!

17

You can add the indent to all the cells in the first column (that should be left aligned) and remove the indent when you want it to:

\documentclass{article}
\usepackage{caption,booktabs,array}

\newcommand{\rowgroup}[1]{\hspace{-1em}#1}

\begin{document}

\begin{table}
\caption{Table}
\centering
\begin{tabular}{>{\quad}lcccc}
\toprule
& \multicolumn{4}{c}{Lags}\\
 & 5 & 10 & 15  & 20 \\
\midrule
\rowgroup{EUR/USD} \\
Ljung-Box-Test & 0,4936 & 0,7841 & 0,8457 & 0,8822 \\
Foo-Test & 0,4936 & 0,7841 & 0,8457 & 0,8822 \\
Foo-Box-Test & 0,4936 & 0,7841 & 0,8457 & 0,8822 \\
\midrule
\rowgroup{USD/EUR} \\
Ljung-Box-Test & 0,4936 & 0,7841 & 0,8457 & 0,8822 \\
Foo-Test & 0,4936 & 0,7841 & 0,8457 & 0,8822 \\
Foo-Box-Test & 0,4936 & 0,7841 & 0,8457 & 0,8822 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

|improve this answer|||||
1

It's not really clean, but I added a blank column on the left, I aligned the second column (with Ljung-Box-Test) right, and for the EUR/USD it's a multicolumn, aligned left...

Here is the code :

\begin{table}
    \caption{Table}
    \centering
    \begin{tabular}{rrcccc}
        \toprule
        & &\multicolumn{4}{c}{Lags}\\[\defaultaddspace]
         & & 5 & 10 & 15  & 20 \\[\defaultaddspace]
         \multicolumn{2}{l}{EUR/USD} &  &  &  &  \\[\defaultaddspace]
         & Ljung-Box-Test & 0,4936 & 0,7841 & 0,8457 & 0,8822 \\
        \bottomrule
    \end{tabular}
\end{table}

And it produces this : My solution

I hope this fits your wishes...

|improve this answer|||||
0

In my opinion, there is a simpler way by using \hspace function, like \hspace{5mm}. More info in How do I indent text within a tabular environment?

Using \rowgroup is problematic with the tabular package, because you cannot use some functions like \resizebox{}.

|improve this answer|||||

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.