1

I am trying to create a table that spans the width of the page, with two columns, aligned right-ragged and left-ragged respectively. However, this is proving weirdly difficult, as I cannot seem to get my tables to behave the way I want them too width-wise.

An example of what I've tried:

\begin{tabular*}{\pagewidth}{l r}
\gray \textbf{Endpoint} & \textbf{0}\\
\end{tabular*}

It seems like a simple problem but the inconsistency of table behavior in LaTeX is really getting to me. Help would be appreciated; perhaps I need to use a minipage?

Edit:

\documentclass[a4paper, oneside, final, 10pt]{scrartcl} % Paper options using the scrartcl class
\usepackage{scrpage2} % Provides headers and footers configuration
\usepackage{titlesec} % Allows creating custom \section's
\usepackage{marvosym} % Allows the use of symbols
\usepackage{tabularx,colortbl} % Advanced table configurations
\usepackage{fontspec} % Allows font customization

\defaultfontfeatures{Mapping=tex-text}
\titleformat{\section}{\large\scshape\raggedright}{}{0em}{}[\titlerule]
\pagestyle{scrheadings}
\addtolength{\voffset}{-1in}
\addtolength{\textheight}{5cm}
\newcommand{\gray}{\rowcolor[gray]{.90}}

\begin{document}

\begin{center} % Center everything in the document

\begin{tabular*}{\pagewidth}{l r}
\gray \textbf{Apple} & \textbf{Banana}\\
\gray Apple & \textbf{Banana}\\
\gray Apple & \textbf{Banana}\\
\end{tabular*}
\begin{itemize} \itemsep1pt \parskip0pt \parsep0pt
\item Apple
\item Apple
\item Mango
\end{itemize}
\end{center}

\end{document}
  • Welcome to TeX.SX! Please provide a working document, not just fragments of code. \pagewidth seems weird and is no usually defined length, in addition there are margins to be considered as well! -- What is \gray supposed to do? –  Oct 18 '15 at 03:22
  • This snippet is not long enough? Unfortunately the full document includes a lot of personally identifiable information (it's a resume) that would take me a long time to edit out, so I am very hesitant to paste it here. – Aleksey Bilogur Oct 18 '15 at 03:38
  • You want to have some help from us but you require to make document around that snippet, i.e. typing work to do. Why should we do that for you? –  Oct 18 '15 at 03:39
  • 1
    @ResMar: We don't want any personal information. See how to create a minimal working example (MWE)... – Werner Oct 18 '15 at 03:42
  • Ok, I made one. – Aleksey Bilogur Oct 18 '15 at 03:53
  • Off-topic: The usage of titlesec together with a KOMA class like scrartcl isn't recommended –  Oct 18 '15 at 03:55

2 Answers2

1

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage{lipsum}% Just for this example
\begin{document}

\lipsum[2]

\begin{table}[ht]
  \makebox[\textwidth]{% https://tex.stackexchange.com/q/16582/5764
    \begin{tabularx}
        {\pdfpagewidth}
        {>{\raggedright}X>{\raggedleft\arraybackslash}X}
      \lipsum*[2] &
      \lipsum*[2]
    \end{tabularx}%
  }
\end{table}

\lipsum[2]

\end{document}

With some help from [Center figure that is wider than \textwidth]Center figure that is wider than \textwidth) you can center content within the text block.

Werner
  • 603,163
1

The tabularx package will do it.

\noindent
\begin{tabularx}{\linewidth}
    {>{\raggedright}X >{\raggedleft \arraybackslash}X}
\gray \textbf{Apple} & \textbf{Banana}\\
\gray Apple & \textbf{Banana}\\
\gray Apple & \textbf{Banana}\\
\end{tabularx}

gives you the first column left-aligned and the second one right-aligned, spanning the page:

grey lines indicate margins

Edit: changed examples to suit your code.

vstepaniuk
  • 423
  • 4
  • 7
  • One would need \noindent as well. Also, only the second \arraybackslash is necessary. – Werner Oct 18 '15 at 04:07
  • What is \noindent for? I added it in several places and it didn't appear to make a difference. Edited to remove the first \arraybackslash. – Tranquilled Oct 18 '15 at 04:10
  • 1
    Without it, the tabularx alone will be indented with \parindent, causing an overfull \hbox since it's width is \linewidth. – Werner Oct 18 '15 at 04:12
  • Thank you for the advice. I did not see an overfull \hbox warning when I ran it. – Tranquilled Oct 18 '15 at 04:16