1

My table is aligned to the left by using \hskip-1.50cm. When I increase the font size from 10pt to 12pt, the table's layout shifts to the right and understandably so. The alternating rowcolors do not completely fill up the last column. Is there an easy way to fix this?

\documentclass[a4paper,10pt]{article}
\newcommand*{\thead}[1]{\multicolumn{1}{c}{\bfseries #1}}
\usepackage[table]{xcolor}

\begin{document}

\rowcolors{2}{gray!10}{orange!5}
\hskip-1.50cm
\begin{tabular}{| c | c | c | p{2cm} | }

\thead{Degree} & \thead{Institution} & \thead{Year of Graduation} & \thead{Distinction} \\ \hline
Degree1 &  Longer University1 &  year1 & Long Distinction1 \\ \hline

Degree2 (sub1) &  LongName University2 &  year2 & Distinction2 \\ \hline

Degree3 (sub3, sub4) &  LongerName University3 &  year3 & Distinction3 \\ \hline

Degree4 (subject1, subject2) &  LongestName University4 &  year4 & Distinction4 \\ \hline

\end{tabular}
\end{document}
1

Increasing the font size from 10 to 12 pt increases the widths of the unbreakable header cells, in the process making the entire table wider than the text block. I suggest you use a tabularx environment instead of tabular and allow line breaks in all four columns.

Since you're using alternating colors to provide visual distinctions between rows, you can dispense with the \hline instructions. You can also remove the vertical bars.

Use \noindent to left-align the tabular material; this without having to know the current value of \parindent.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage[table]{xcolor}
\usepackage{tabularx,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash\hspace{0pt}}X}
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}
\begin{document}

\rowcolors{2}{gray!10}{orange!5}
\noindent    
\begin{tabularx}{\textwidth}{ LCCC  }
\textbf{Degree} & \textbf{Institution} & \textbf{Year of Graduation} & \textbf{Distinction} \\
Degree1 &  Longer University1 &  year1 & Long Distinction1 \\
Degree2 (sub1) &  LongName University2 &  year2 & Distinction2 \\
Degree3 (sub3, sub4) &  LongerName University3 &  year3 & Distinction3 \\
Degree4 (subject1, subject2) &  LongestName University4 &  year4 & Distinction4 \\ 
\end{tabularx}
\end{document}

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.