2

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}
1
  • you have defined only two column table ...
    – Zarko
    Aug 17, 2017 at 15:57

1 Answer 1

3

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}
1
  • Thanks for this helpful suggestion. This suggestion solves the problem.
    – Job
    Aug 19, 2017 at 8:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .