1

I have used colour to mark some cells in a table, but the final cell (right, bottom) seems to "overflow".

\documentclass[nols,notitlepage,openany,12pt,table,xcdraw]{tufte-handout}

\usepackage{geometry}
\geometry{a4paper,bottom=1.5in}

\usepackage{fontspec}
\setmainfont[Mapping=tex-text,Numbers=OldStyle]{Minion Pro}
\setsansfont[Mapping=tex-text,Numbers=OldStyle]{Gill Sans}

\usepackage{booktabs}

\usepackage{enumitem}
% \setlist{nolistsep} % or \setlist{noitemsep} to leave space around whole list
\setlist{noitemsep}
\usepackage{adjustbox}
\begin{document}


\begin{table}[h!]
\begin{tabular}{@{}lllll@{}}

2020 & 2021 & 2022                                           & 2023-25                                & 2025-2030                                     \\ \midrule
\multicolumn{5}{l}{\cellcolor[HTML]{EFEFEF}Individuella ansökningar}                                                                                  \\
     & \multicolumn{4}{l}{\cellcolor[HTML]{EFEFEF}Gemensamma ansökningar}                                                                             \\
     &      & \cellcolor[HTML]{EFEFEF}Strategisk publicering & \cellcolor[HTML]{EFEFEF}Programansökan &                                               \\
     &      &                                                &                                        & \cellcolor[HTML]{EFEFEF}Lansering av institut
\end{tabular}
\end{table}

\end{document}

Output:

problematic overflow in final cell of table

It does not solve itself by writing less in the final cell.

  • it's the @{} use \multicolumn{1}{>{\columncolor[HTML]{EFEFEF}}{l@{}} instead of \cellcolor – David Carlisle Sep 24 '19 at 13:59
  • Aha, I got the code from tablesgenerator.com – trmdttr Sep 24 '19 at 14:07
  • Sorry, @DavidCarlisle, I can't seem to fix it – should I change something on the two last rows as well? It doesn't seem to work if I only change the multicolumn rows. Maybe there is another better approach I should use. – trmdttr Sep 24 '19 at 14:12
1

Use <{\kern-\tabcolsep}, also necessary in the multicolumns, and add \\ to the last row. I you have p/m/b-columns, you have to take special steps, see this question and its answers:

enter image description here

\documentclass[12pt,table,xcdraw]{article}
\usepackage{geometry}
\geometry{a4paper,bottom=1.5in}
\usepackage{booktabs, xcolor}

\begin{document}

\begin{table}
\begin{tabular}{>{\kern-\tabcolsep}lllll<{\kern-\tabcolsep}}

2020 & 2021 & 2022                                           & 2023-25                                & 2025-2030                                     \\ \midrule
\multicolumn{5}{>{\kern-\tabcolsep}l<{\kern-\tabcolsep}}{\cellcolor[HTML]{EFEFEF}Individuella ansökningar}                                                                                  \\
     & \multicolumn{4}{l<{\kern-\tabcolsep}}{\cellcolor[HTML]{EFEFEF}Gemensamma ansökningar}                                                                             \\
     &      & \cellcolor[HTML]{EFEFEF}Strategisk publicering & \cellcolor[HTML]{EFEFEF}Programansökan &                                               \\
     &      &                                                &                                        & \cellcolor[HTML]{EFEFEF}Lansering av institut\\
\end{tabular}
\end{table}
\end{document}
| improve this answer | |
  • That works! Although the last line in the last cell gets no (grey) whitespace on the right… – trmdttr Sep 24 '19 at 14:13
  • Ah, sorry! Missed the \strut. Works perfectly – trmdttr Sep 24 '19 at 14:14
  • For me, it works without \strut for me, but I have an updated array package. Be aware of special requirements if you have p-columns. See updated answer – Sveinung Sep 24 '19 at 14:16

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.