1

I currently have a tabularx table with four columns. I initialize the environment like this:

\begin{tabularx}{\linewidth}{l p{0.4\linewidth} | l X l X}

How could I change this so that the second column (p{0.4\linewidth}) extends to, but not past the center of the page?

  • This would depend on the width of the first l-column. If you can fix the first column to some width (also using a p-column), then you can define the second column to be the residual. Also, may some more information about the table contents could suggest other ways of constructing what you're after. – Werner Oct 5 '14 at 4:54
1

With two successive tables?

\documentclass{article}
    \usepackage{tikz}
%---------------------------------------------------------------%
    \usepackage{booktabs,tabularx,calc}

\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}

\begin{document}
\begin{table}
    \begin{tabularx}{0.5\linewidth}{lX@{}}  %%% first table
    \hline
        1. column    &   2. column \\
        1. column    &   2. column \\
    \hline
        \end{tabularx}%  
    \begin{tabularx}{0.5\linewidth}{|lXX}               %%% second table
    \hline
        3. column    &   4. column   &   5.column \\
        3. column    &   4. column   &   5.column \\
    \hline
        \end{tabularx}
\end{table}
\end{document}

enter image description here

Edit: Thank to Mico I rethinking my answer. Above example work only if you have only one line in second column cells. In case, that in those cels will heve longer text, than the possible solution is to pot table in table:

\documentclass{article}
%---------------------------------------------------------------%
    \usepackage{booktabs,tabularx,calc} 
\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}

\begin{document}
\begin{table}
    \begin{tabularx}{\linewidth}{@{}l|lXX}               
    \hline
{\begin{tabularx}{0.5\linewidth}{lX}  %%% first table in table
1.  &   2. column, but this doesn't work,
                    if the content of this cell is very long,
                    i.e. spread over more line
\end{tabularx}}
    &   3.  &   4. column   &   5. column \\
        \hline
{\begin{tabularx}{0.5\linewidth}{lX}  %%% second table in table
1.  &   2. column, with short text
\end{tabularx}}%
    &   3.  &   4. column   &   this column also can has 
                                longer text span over more lines\\
    \hline
        \end{tabularx}
\end{table}
\end{document}

enter image description here

Now I must confess that I'n not sure anymore, if you like that second cill always finish in the middle of page (text).

  • The OP didn't ask for a vertical bar in the table, so I wouldn't supply one. You may also want to check your column numbering scheme. – Mico Oct 5 '14 at 4:08
  • Mico, I do not understand your comment. OP show vertical line after second column, content of columns is dummy and I do not figure out what you mean with column numbering scheme. I edit my answer a bit. – Zarko Oct 5 '14 at 4:55
  • I do not understand you comment completely. Now I see, that given MWE work fine only if cells in the second column have only one line, otherwise, lines of both tables doesn't align any more. Later I will correct my unswer – Zarko Oct 5 '14 at 5:01
  • That works pretty well; I hadn't thought of that at all. Thank you! – user184745 Oct 5 '14 at 5:31
  • @Zarko - Glad you found my comments useful (though admittedly a bit terse). About the numbering issue: the code in the first example numbers the columns 1 through 5, but the screenshot shows the numbers 1, 2, 3, 5, and 6... – Mico Oct 5 '14 at 6:48

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.