3

I'm facing some issues with my two-column table. The second column which contains a description is causing problems. I want the second column to automatically begin a new line whenever it is exceeding the text width of the document.

Also, I have a problem regarding placement of titles within the table. Currently, as you can see, text in the second column is being moved over by the "Case 1" title from column one. Ideally, the first column should not affect the second in this manner.

This is my code:

  \documentclass[12pt,twoside]{book}
\usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}      

\usepackage{amsmath}                      
\usepackage{mathtools} 
\usepackage{tabularx}                     
\usepackage{subcaption}
\usepackage{booktabs}   

\begin{document}
        \begin{table}[H] 
    \centering
    \begin{tabular}{llp{4cm}}
    \toprule
    \textbf{Variable} & \textbf{Definition}   \\
    \midrule
    \textbf{General variables} \\
    $K$ & Fixed amount of money need to start production \\
    $s$ & Baseline quality of the good (normalized to 1) \\
    $n$ & Number of people \\
    $\pi_1, \pi_2, \Pi$ & Profits of the entrepreneur in the first period ($\pi_1$), in the second period ($\pi_2$) and total profits $\Pi = \pi_1 + \pi_1$) \\
    $P_r$ & $P_r$ is the regular price \\
    \textbf{Case 1: This is a very long title2} \\
    $\alpha$ & $\alpha$ is specific for Case 1 \\
    \bottomrule
    \end{tabular}
    \floatfoot{ \textit{Note}: This table....
                \textit{Source}: Source to be inserted}
    \caption{Definition of variables}
    \label{table_alm}
    \end{table}

\end{document}

This is the current output:

enter image description here

  • 1
    fully compilable MWE please. – naphaneal Apr 4 '16 at 14:37
  • 1
    why have you specified four columns? – David Carlisle Apr 4 '16 at 14:41
  • @Naphaneal Done – Saud Apr 4 '16 at 14:51
  • @DavidCarlisle, reused the code from a previous table in my document. – Saud Apr 4 '16 at 14:52
  • 1
    It just complicates your code (and possible answers) l and r are single line, you presumably want to make one column be a p column and (because you made Variable span both columns) you get spurious column padding either side of the empty r columns. – David Carlisle Apr 4 '16 at 14:57
4

Try this:

     \documentclass[12pt,twoside]{book}
  \usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}      

  \usepackage{amsmath}                      
  \usepackage{mathtools} 
  \usepackage{tabularx}                     
  \usepackage{subcaption}
    \usepackage{booktabs}   

    \begin{document}
    \begin{table}[H] 
    \centering
    \begin{tabular}{lp{6cm}}
        \toprule
        \textbf{Variable} & \textbf{\hskip-1.2in Definition}   \\
        \midrule
        \textbf{General variables} \\
        $K$ & \hskip-1.2in Fixed amount of money need to start production \\
        $s$ & \hskip-1.2in Baseline quality of the good (normalized to 1) \\
        $n$ & \hskip-1.2in Number of people \\
        $\pi_1, \pi_2, \Pi$ & \hskip-1.2in%
 \vtop{\hsize=3.5in Profits of the entrepreneur in the first period ($\pi_1$),%
 in the second period ($\pi_2$) and total profits $\Pi = \pi_1 + \pi_1$)} \\
        $P_r$ & \hskip-1.2in $P_r$ is the regular price%
   \vspace{.05in}\\
         \textbf{Case 1: This is a very long title2} \\
        $\alpha$ & \hskip-1.2in $\alpha$ is specific for Case 1 \\
        \bottomrule
    \end{tabular}
     \vskip.1in\par
     {\textit{Note}: This table....
        \textit{Source}: Source to be inserted}
    \caption{Definition of variables}
    \label{table_alm}
\end{table}

  \end{document}

Which produces: enter image description here

  • @A Feldman, thank you for your input! I just need the "Definition" title to b left-centered. I tried with "\begin{tabular}{llp{7cm}}" and "\textbf{Variable} & {l}\textbf{Definition}", but it didn't work. Also tried using "\raggedleft" but it crashed in the tabular-environment. – Saud Apr 6 '16 at 9:18
  • 1
    @Saud I went ahead and moved "Definition" over. Is that what you were looking for? – A Feldman Apr 6 '16 at 13:13
  • Mission accomplished! :) – Saud Apr 6 '16 at 13:35
  • Good, glad that it works for you. – A Feldman Apr 6 '16 at 13:43

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.