1

I am trying to construct a table with three columns in which I can fit a long text within the middle column. The code works well for 2 columns but not 3. Could some please help out?

\documentclass{article}

\newlength\mylength
\setlength\mylength{\dimexpr.5\columnwidth-2\tabcolsep-0.5\arrayrulewidth\relax}

\begin{document}

\begin{table}
    %% \centering % not needed
    \caption{Simulation parameters}
    \begin{tabular}{p{\mylength}|p{\mylength}}
        \hline
    \textbf{Variable} &\textbf{Defintion} &  \textbf{Source}    \\\hline \\
        \hline
ABCDEF & Long Text Long Text LongLong Text Long Text LongLong Text Long Text LongLong Text Long Text LongLong Text Long Text Long Text & Database Name  \\ \\

        \hline
    \end{tabular}
    %\label{table: simulation parameters}
\end{table}

\end{document}
  • you have defined only two column table ... – Zarko Aug 17 '17 at 15:57
2

your code for table has more issues:

  • defined are two columns, but you use three
  • instead \\ \hline \\ \hline should be \\ \hline\hline
  • table is not well balanced. you should reconsider its design, for example use of tabularx and l column type in the first column, X for the second column and whatever for the last (it is not clear requirement for it)

\documentclass{article}

\begin{document}

\begin{table}
    %% \centering % not needed
    \caption{Simulation parameters}
    \begin{tabular}{*{3}{p{\dimexpr0.33\linewidth-2\tabcolsep\relax}}}
        \hline
    \textbf{Variable} & \textbf{Defintion} &  \textbf{Source}    \\
        \hline\hline
ABCDEF & Long Text Long Text LongLong Text Long Text Long Long Text Long Text Long Long Text Long Text Long Long Text Long Text Long Text & Database Name  \\
        \hline
    \end{tabular}
    %\label{table: simulation parameters}
\end{table}

\end{document}

enter image description here

for example a table version with tabularx and booktabs:

enter image description here

\documentclass{article}
\usepackage{booktabs, tabularx}

\begin{document}

\begin{table}[ht]
\caption{Simulation parameters}
    \begin{tabularx}{\linewidth}{ l X l}
        \toprule
    \textbf{Variable} & \textbf{Defintion} &  \textbf{Source}    \\
        \midrule
ABCDEF & Long Text Long Text LongLong Text Long Text Long Long Text Long Text Long Long Text Long Text Long Long Text Long Text Long Text & Database Name    \\
        \bottomrule
    \end{tabularx}
    %\label{table: simulation parameters}
\end{table}

\end{document}
  • Thanks for this helpful suggestion. This suggestion solves the problem. – Job Aug 19 '17 at 8: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.