1

What I want to do is make a table in the format that I have showed below. At the moment the width of the columns is different and the table is to wide for the page. It looks as following: enter image description here

What I am trying to do is

1) set the table to be as wide as the text, so that it takes up maximum space within the margins

2) set that column 2, 3 and 4 that contain the results are the same width.

\begin{table}[H] \centering \caption{X} \label{X}
\begin{tabular}{cccc}
        \textbf{References} & \textbf{Results 1} & \textbf{Results 2} & \textbf{Results 3} \\\hline\hline

    Author (Year)
    & 
    Answer Answer 
    & 
    Answer Answer Answer Answer 
    & 
        \begin{tabular}{c} 
        Answer Answer Answer Answer Answer Answer  \\
        Answer Answer Answer  \\ 
        \end{tabular} 
    \\\hline

    Author (Year) & 
        \begin{tabular}{c} 
        Answer \\ 
        Answer \\ 
        \end{tabular}
    &
    Answer Answer 
    &
        \begin{tabular}{c} 
        Answer Answer Answer  \\ 
        Answer Answer Answer  \\ 
        \end{tabular}
    \\\hline   

    Author (Year) & 
    \begin{tabular}{c} 
    Answer \\ 
    Answer \\ 
    Answer \\ 
    \end{tabular} 
    &
    \multicolumn{2}{c}{Answer Answer Answer Answer Answer Answer Answer Answer }
    \\\hline 
\end{tabular}
\end{table}
  • Welcome to TeX-SE! Are you looking for tabularx? – user121799 Feb 27 at 4:17
1

with tabularx is no need to nest tables:

\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs, tabularx}
\usepackage[skip=1ex]{caption}

\begin{document}
    \begin{table}[htb]
    \caption{X} 
    \label{X}
\begin{tabularx}{\linewidth}{@{} l *{3}{>{\centering\arraybackslash}X} @{}}
    \toprule
\textbf{References} & \textbf{Results 1} & \textbf{Results 2} & \textbf{Results 3}  \\
    \midrule
Author (Year)       
    &  Answer Answer    
        &   Answer Answer Answer Answer
            &   Answer Answer Answer Answer Answer Answer 

                Answer Answer Answer                                                \\
    \midrule
Author (Year) 
    &   Answer 

        Answer
        &   Answer Answer
            &   Answer Answer Answer 
                Answer Answer Answer                                                \\
    \midrule
Author (Year) 
    &   Answer

        Answer

        Answer
        &   \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep\relax
                              \centering\arraybackslash}X}{%
            Answer Answer Answer Answer Answer Answer Answer Answer }               \\
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}

enter image description here

instead of horizontally centered cells text i would rather have left aligned, i.e. instead of >{\centering\arraybackslash}X use >{\raggedright\arraybackslash}X

  • +1. Since there are no vertical rules in the table, one can (should...) omit the \arrayrulewidth adjustment. – Mico Feb 27 at 7:12
  • @Mico, during tests it was there, but then i erase it and forget to correct calculation of columns width. thank you very much! – Zarko Feb 27 at 9:03

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.