0

Problem solved: Package ltablex was loaded before tabularx and thus it didn't work. Using tabularx is working now!

So I would like to set up a table over the whole textwidth with two columns. It's almost working, except the right column is shifted to the right and I don't know how to fix this.

I tried to adapt the solution from this question: Setting table-width exactly to linewidth and this is the code

\documentclass[a4paper, 11pt, oneside]{scrbook}
%\usepackage{tabularx}
\begin{document}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|l|l|}
    \hline
    left column & right column \\
    \hline
    left column & right column
    \hline
\end{tabular*}
\end{document}

but this is the result:

Latex table with two columns over linewidth with wrong column space

Why is the right column so much shifted to the right? And the left column has zero space to the right. How can I fix this so that the left column uses as much space as needed and the right column fills the linewidth?

My desired output should look like this:

enter image description here

With the left column only using as much space as needed and the right column filling up the rest of the horizontal space.

I already tried it with tabularx but this isn't working either:

\documentclass[a4paper, 11pt, oneside]{scrbook}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\linewidth}{|X|X|}
    \hline
    left column & right column \\
    \hline
    left column & right column \\
    \hline
\end{tabularx}
\end{document}

Here is the result:

Not working two column table example with tabularx

Thanks in advance!

  • 1
    Welcome to TeX.SX! Use \noindent before the table. ->\noindent \begin{tabular*}. WIth \usepackage{showframe} you could visualize margins. – Bobyandbob Nov 19 '17 at 21:28
  • Why not use the tabularx package and its flexible width X column? – leandriis Nov 19 '17 at 21:30
  • Thank you! I didn't see the indent but this isn't my main problem. The right column should be left aligned next to the left column without that huge horizontal space in between. – Robert Nov 19 '17 at 21:30
  • Already tried tabularx but with tabularx it isn't working at all. Will update the question with my tabularx example – Robert Nov 19 '17 at 21:33
  • @Robert: could you please turn your code fragment into a compilable MWE? With the information you posted, I am not able to recreate the issue you have with tabularx. – leandriis Nov 19 '17 at 21:37
0

Use this column specification:

\documentclass[a4paper, 11pt, oneside]{scrbook}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\linewidth}{|l|X|}
    \hline
    left column & right column \\
    \hline
    left column & right column \\
    \hline
\end{tabularx}
\end{document}

enter image description here

  • Problem solved... I had the package ltablex loaded before tabularx and thus it didn't work. It now works and your solution is the best looking! – Robert Nov 19 '17 at 21:56
0

It does work with tabularx:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}

\begin{document}

\begin{tabularx}{\linewidth}{|X| >{\arraybackslash}X|}
    \hline
    left column & right column \\
    \hline
    left column & right column \\
    \hline
\end{tabularx}

\end{document} 

enter image description here

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.