Graphics, Figures & TablesTrouble with my tabular code: seven questions

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Wafflehousedreamer
Posts: 1
Joined: Wed Jan 05, 2022 3:24 pm

Trouble with my tabular code: seven questions

Post by Wafflehousedreamer »

Here is the code that I am using. My questions are below.

Code: Select all

\documentclass[12pt]{article}
\usepackage{titlesec}
\usepackage{titling}
\usepackage[margin=1in]{geometry}
\geometry{headheight=15pt}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}

\usepackage[T1]{fontenc}
\usepackage{enumitem}
\usepackage[dvipsnames]{xcolor}

\usepackage[british]{babel}
\usepackage{csquotes}

\titleformat{\section}
{\fontsize{15pt}{15}\bfseries}
{}
{0em}
{}[\titlerule]

\titleformat{\subsection}
{\fontsize{14pt}{15}}
{}
{.4em}
{}

\renewcommand{\maketitle}{

{\Large
\setlength{\parindent}{0em} \theauthor}
}

\usepackage{setspace}
\setstretch{1.2}

\addtolength{\skip\footins}{1pc}
\setlength{\footnotesep}{1.5pc}

\usepackage[symbol]{footmisc}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\usepackage{soul}
\setul{1ex}{}

\thispagestyle{empty}

\definecolor{lightgray}{gray}{0.8}
\usepackage{array}
\newcolumntype{L}{>{\raggedright}p{0.825\textwidth}} #I would rather justify this column#
\newcolumntype{R}{p{0.65\textwidth}} #I have no idea what this 0.65 value value actually does, nor how to align this column to the right instead#
\newcommand\VRule{\color{lightgray}\vrule width 0.5pt}

\usepackage{hanging}
\usepackage{ragged2e}

\begin{document}

…

\section{Nutritional Representation}

\vspace{.25em}

\begin{tabular}{L!{\VRule}R}
\begin{tabular}{L!{\VRule}R}
Broccoli Representative & 2018--2019\\
\vspace{0em}
Cauliflower Representative & 2020--2021\\
\vspace{0em}
Cabbage Representative & 2021--2022\\
\end{tabular}

\vspace{.2em}

…
\end{document}

I made a tabular using this code (with some dummy values inserted above because the real code is for my CV). I have several questions about it.

First, how can I justify the left column? Right now I’m using the ragged2e package and manually doing it in every instance where I want justified text. Which is fine, but I thought there would be a cleaner way to do it globally.

Second, when I do this, the justified text is far too close to the vrule. Is there a way to control the amount of space between the text and the vrule?

Third, for this line: \newcolumntype{R}{p{0.65\textwidth}}, what is the 0.65 value (I’ve been playing with it and it appears to do nothing), and fourth, how do I align the right column to the right (instead of the left). (I’m using a hackey workaround right now that works fine.)

Fifth, I’ve noticed that when the tabular gets too large, it starts on the next page instead of where I want it. How can I fix this? One solution is just to break up the table in each instance on different pages. That’s a one-off solution.

Sixth, I’ve noticed that when the tabular gets too large, the rest of the tabular disappears into a phantom next page, and doesn’t appear on the actual next page. How can I fix this? One solution is just to break up the table in each instance on different pages. That’s another one-off solution.

Seventh, is there a better tabular/table code that is more suitable to my needs? Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Trouble with my tabular code: seven questions

Post by rais »

Wafflehousedreamer wrote: First, how can I justify the left column? Right now I’m using the ragged2e package and manually doing it in every instance where I want justified text. Which is fine, but I thought there would be a cleaner way to do it globally.
Just drop the >{\raggedright} from the L-column's specification.
Wafflehousedreamer wrote: Second, when I do this, the justified text is far too close to the vrule. Is there a way to control the amount of space between the text and the vrule?
I don't see that here. Perhaps I dropped too much of your code... BTW: the code you presented doesn't really show any of your problems.
Wafflehousedreamer wrote: Third, for this line: \newcolumntype{R}{p{0.65\textwidth}}, what is the 0.65 value (I’ve been playing with it and it appears to do nothing),
0.65<length> means 65 percent of that <length>. In this case you're trying to put 0.65\textwidth next to something already 0.825\textwidth wide...see also my comments in the code below.
Wafflehousedreamer wrote: and fourth, how do I align the right column to the right (instead of the left).
Well, use >{\raggedleft} or since you're using ragged2e package >{\RaggedLeft} in the R column's specification.
Wafflehousedreamer wrote: Sixth, I’ve noticed that when the tabular gets too large, the rest of the tabular disappears into a phantom next page, and doesn’t appear on the actual next page. How can I fix this? One solution is just to break up the table in each instance on different pages. That’s another one-off solution.
Yes, tabular does not allow page breaks. For this reason, packages like supertabular and longtable exist ;)
Wafflehousedreamer wrote:
Seventh, is there a better tabular/table code that is more suitable to my needs? Thanks.
I've written my last CV over two decades ago so I'm not sure what would suit you best. However, there are specialized classes for writing a curriculum vitae using LaTeX.

I dropped some of your code, e.g., your redefinition of \maketitle isn't necessary for your {tabular} problems...and then it wasn't even used.

Code: Select all

\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\geometry{headheight=15pt}

\usepackage[T1]{fontenc}
\usepackage[dvipsnames]{xcolor}
\usepackage[british]{babel}
\usepackage{lipsum}% just for demo
\definecolor{lightgray}{gray}{0.8}
\usepackage{ragged2e}
\usepackage{array}
\newcolumntype{L}{p{0.825\textwidth}} %#I would rather justify this column#<-- dropped the >{\raggedright} specification
\newcolumntype{R}{>{\RaggedLeft}p{\dimexpr0.175\textwidth-4\tabcolsep-0.5pt\relax}} %#I have no idea what this 0.65 value value actually does, nor how to align this column to the right instead#<-- 0.65\textwidth means 65% of \textwidth. Putting that next to a column that already spans 82.5% of \textwidth pushes most of your second column outside the page. Even the remainder with 17.5% would be a little bit too much,because columns are padded sideways by \tabcolsep wide spaces.
\newcommand\VRule{\color{lightgray}\vrule width 0.5pt}


\begin{document}

\section{Nutritional Representation}

\makebox[0pt][l]{\color{blue!40}%
\rule{\tabcolsep}{1pt}% padding left of first column
\rule{0.825\textwidth}{1pc}% the active area of first column
\rule{\tabcolsep}{1pt}% padding right of first column
\rule{0.5pt}{1pc}% the width of your \VRule
\rule{\tabcolsep}{1pt}% padding left of second column
\rule{\dimexpr0.175\textwidth-4\tabcolsep-0.5pt\relax}{1pc}% the active area of second column
\rule{\tabcolsep}{1pt}% padding right of second column
}% just for demo
\begin{tabular}[t]{L!{\VRule}R}%<-- [t] only for demo to align top line with my rules from above
Broccoli Representative & 2018--2019\\
Cauliflower Representative & 2020--2021\\
\lipsum[1] %<-- to demonstrate text is now justified 
  & 2021--22\\%<-- to demonstrate right aligned R column
\end{tabular}

BTW: \verb!\textwidth! is \the\textwidth\ wide in this document.
\end{document}
KR
Rainer
Post Reply