3

I'm trying to create my class routine in latex, but it renders partially:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}[]
    \begin{tabular}{lllllllllll}
            & 9.00-9.45 & 9.50-10.35 & 10.40-11.25 & 11.30-12.15 & 12.20-1.05 & 1.05-1.30 & 1.30-2.15 & 2.30-3.05 & 3.10-3.55 & 4.00-4.45 \\
        Sun &           & 717        & 717         &             &            & *         &           &           &           &           \\
        Mon & 715       & 715        & 711         & 711         & 712        & *         & 712       & 719       & 719       &           \\
        Tue &           &            &             &             &            & *         &           & 716       & 716       &           \\
        Wed &           & 711        & 713         & 714         & 714        & *         & 717       & 717       & 719       & 719       \\
        Thu &           &            &             &             &            & *         & Thesis    & Thesis    & Thesis    & Thesis    
    \end{tabular}
\end{table}
\end{document}

I tried different points in documentclass, even 6 point but it doesn't fit in the pdf.

I even tried adjustbox, but for some unknown reason texwork doesn't recognize it and can't even install it. So is there anyway I can render it completely ?

Current render :

enter image description here

6
  • 1
    article class has 10pt,11pt and 12pt options it does not take arbitrary lengths like 6pt, you can make the table smaller by using a smaller font such as \footnotesize Jan 4, 2020 at 13:26
  • Do you want just this table or is it a part of a document? There are different strategies to include such large tables. If this is just one single table without any text use class standalone.
    – Niranjan
    Jan 4, 2020 at 13:59
  • Also transposing the table might be an idea (making the days into columns and the dates into rows).
    – Skillmon
    Jan 4, 2020 at 14:12
  • Can you change (decrease) the margins of your document? An alternative yould be rotating the table to a landscape orientation. You could also introduce linebreaks in the column headers.
    – leandriis
    Jan 4, 2020 at 14:18
  • @MaifeeUlAsad were you able to select any of the responses to your question
    – js bibra
    Jan 12, 2020 at 12:28

4 Answers 4

6

Here are four MWEs that fit within their margins.

I used scrartcl from KOMA-script to have more sensible margins. You can achieve the same by loading geometry. Also, consider allowing some more vertical space (air) in the tabular. Load the array package and add the following two commands to the preamble:

\setlength{\extrarowheight}{1pt}
\renewcommand{\arraystretch}{1.1}

See the effect in example 3.

Example 1: I reduced the font size to small. scrartcl standard is 11 pt. Also, I defined a \thead macro for the ten headings. The text is set in a narrow p-column, and aligned at the right margin. In addition, I aligned all the column at the right, except the first and sixth.

At last, I loaded booktabs, and set a \midrule after the heading and removed the side bearings at the left and right side of the tabular, see the @{} in the definition of the tabular.

Example 2: Here, I used tabular* instead of tabular. I set \tabcolsep to 0, and let tabular* calculate the space between columns. In addition, I reduce the width of the heading cells untill all had line breaks.

Example 3: This is probably the simplest solution and what I recommend for you: Load the excellent tabulary package and let LaTeX do all the calculation. I reduced \tabcolsep slightly more, removed the side bearings and reduced font size as in the other examples. Be aware that the first column is an ordinary l-column. Thereafter, I have 10 right aligned R-columns:

Example 4: Inspired by Bernhard, but slightly different. Due to how \rowcolor and \columncolor work, I removed side bearing by setting \tabcolsep to 0 and added space between columns using very narrow columns (defined as new column type N). The T-column uses a feature described in the dcolumn manual.

Example 1 – using tabular

enter image description here

\documentclass{scrartcl}
\usepackage{graphicx, booktabs}

\newcommand{\thead}[1]{\multicolumn{1}{p{\dimexpr((\linewidth/11)-2\tabcolsep)\relax}}{\raggedleft #1}}

\begin{document}
\begin{table}
\small\centering
\setlength{\tabcolsep}{0.3em}

\begin{tabular}{@{}lrrrrcrrrrr@{}}
   & \thead{9.00--9.45} & \thead{9.50--10.35} & \thead{10.40--11.25}
   & \thead{11.30--12.15} & \thead{12.20--1.05} & \thead{1.05--1.30}
   & \thead{1.30--2.15} & \thead{2.30--3.05} & \thead{3.10--3.55}
   & \thead{4.00-4.45} \\ \midrule
Sun &     & 717 & 717 &     &     & * &        &        &        &       \\
Mon & 715 & 715 & 711 & 711 & 712 & * &   712  &   719  &   719  &       \\
Tue &     &     &     &     &     & * &        &   716  &   716  &       \\
Wed &     & 711 & 713 & 714 & 714 & * &   717  &   717  &   719  &   719  \\
Thu &     &     &     &     &     & * & Thesis & Thesis & Thesis & Thesis \\  
    \end{tabular}
\end{table}
\end{document}

Example 2 – using tabular*

enter image description here

\documentclass{scrartcl}
\usepackage{graphicx, booktabs}

\newcommand{\thead}[1]{\multicolumn{1}{p{\dimexpr(\linewidth/13)}}{\raggedleft #1}}
\setlength{\tabcolsep}{0em}

\begin{document}

\begin{table}
\small\centering
\begin{tabular*}\linewidth{@{\extracolsep{\fill}}l*{10}{r}}
   & \thead{9.00--9.45} & \thead{9.50--10.35} & \thead{10.40--11.25}
   & \thead{11.30--12.15} & \thead{12.20--1.05} & \thead{1.05--1.30}
   & \thead{1.30--2.15} & \thead{2.30--3.05} & \thead{3.10--3.55}
   & \thead{4.00-4.45} \\ \midrule
Sun &     & 717 & 717 &     &     & * &        &        &        &       \\
Mon & 715 & 715 & 711 & 711 & 712 & * &   712  &   719  &   719  &       \\
Tue &     &     &     &     &     & * &        &   716  &   716  &       \\
Wed &     & 711 & 713 & 714 & 714 & * &   717  &   717  &   719  &   719  \\
Thu &     &     &     &     &     & * & Thesis & Thesis & Thesis & Thesis \\  
    \end{tabular*}
\end{table}

\end{document}

Example 3 – tabulary

enter image description here

\documentclass{scrartcl}
\usepackage{graphicx, booktabs, tabulary, array}

\setlength{\extrarowheight}{1pt}
\renewcommand{\arraystretch}{1.1}

\begin{document}

\begin{table}
\small\centering
\setlength{\tabcolsep}{0.2em}
\begin{tabulary}\linewidth{@{}l*{10}{R}@{}}
    & 9.00--9.45\, & 9.50--10.35\,
    & 10.40--11.25\, & 11.30--12.15\,
    & 12.20--1.05\, & 1.05--1.30\,
    & 1.30--2.15\, & 2.30--3.05\,
    & 3.10--3.55\, & 4.00-4.45\, \\ \midrule
Sun &     & 717 & 717 &     &     & * &        &        &        &       \\
Mon & 715 & 715 & 711 & 711 & 712 & * &   712  &   719  &   719  &       \\
Tue &     &     &     &     &     & * &        &   716  &   716  &       \\
Wed &     & 711 & 713 & 714 & 714 & * &   717  &   717  &   719  &   719  \\
Thu &     &     &     &     &     & * & Thesis & Thesis & Thesis & Thesis \\  
\end{tabulary}
\end{table}

\end{document}

Example 4 – tabular, dcolumn and xcolor

enter image description here

\documentclass{article}
\usepackage{geometry}
\usepackage{array, makecell, booktabs, dcolumn}
\usepackage{graphicx}
\usepackage[svgnames, table]{xcolor}

\newcolumntype{N}{wc{1em}}
\newcolumntype{T}{D{-}{-}{5,5}}

\begin{document}
\renewcommand{\arraystretch}{1.15}
\setlength{\extrarowheight}{2pt}
\begin{table}
\centering\small
\setlength{\tabcolsep}{0em}

\begin{tabular}{@{}>{\columncolor{Gainsboro!60!Lavender}}TN*{5}{cN}@{}}
\rowcolor{Gainsboro!60!Lavender}
            && Sunday && Monday && Tueday && Wednesday && Thursday\\
9.00-9.45   &&        &&   715  &&        &&           &&         \\
9.50-10.35  &&   717  &&   715  &&        &&    711    &&         \\
10.40-11.25 &&   717  &&   711  &&        &&    713    &&         \\
11.30-12.15 &&        &&   711  &&        &&    714    &&         \\
12.20-1.05  &&        &&   712  &&        &&    714    &&         \\
1.05-1.30   &&    *   &&    *   &&    *   &&     *     &&    *    \\
1.30-2.15   &&        &&   712  &&        &&    717    && Thesis  \\
2.30-3.05   &&        &&   719  &&   716  &&    717    && Thesis  \\
3.10-3.55   &&        &&   719  &&   716  &&    719    && Thesis  \\
4.00-4.45   &&        &&        &&        &&    719    && Thesis  \\
\end{tabular}
\end{table}
\end{document}
5

I propose one of these solutions, in addition to using a sideways table: either load geometry to have default smaller margins, and use the small font size, or swap rows and columns.

\documentclass{article}
\usepackage{geometry}
\usepackage{array, makecell, booktabs}
\usepackage{graphicx, rotating}
\usepackage[svgnames, table]{xcolor}
\newcommand{\rowhead}[1]{\rotatebox[origin=c]{90}{\,#1\,}}

\begin{document}
\renewcommand{\arraystretch}{1.25}
\begin{table}[]
\centering
\bgroup
\setlength{\tabcolsep}{2.2 pt}
\small
    \begin{tabular}{@{} >{\columncolor{Gainsboro!60!Lavender}}l@{\quad}*{10}{l}@{}}
\cellcolor{white} & \thead{9.00--9.45} & \thead{9.50--10.35} & {10.40--11.25} & \thead{11.30--12.15} & \thead{12.20--1.05} & \thead{1.05--1.30} & \thead{1.30--2.15} & \thead{2.30--3.05} & \thead{3.10--3.55} & \thead{4.00--4.45 }\\
\cmidrule{2-11}
        \rowhead{Sun} & & 717 & 717 & & & * & & & & \\
\addlinespace
        \rowhead{Mon} & 715 & 715 & 711 & 711 & 712 & * & 712 & 719 & 719 & \\
\addlinespace
        \rowhead{Tue} & & & & & & * & & 716 & 716 & \\
\addlinespace
        \rowhead{Wed} & & 711 & 713 & 714 & 714 & * & 717 & 717 & 719 & 719 \\
\addlinespace
        \rowhead{Thu} & & & & & & * & Thesis & Thesis & Thesis & Thesis
    \end{tabular}
\egroup
\vspace{1cm}


\newcolumntype{T}[1]{D{-}{\,\textendash\,}{#1}}
    \begin{tabular}{>{\columncolor{WhiteSmoke}\small}T{4}*{5}{l} }
\rowcolor{Gainsboro!50!Lavender} \multicolumn{1}{c}{\cellcolor{white}} & Sun & Mon & Tue &Wed & Thu \\
\addlinespace
 9.00-9.45 & & 715 \\
9.50-10.35 & 717 & 715 & & 711 \\
10.40-11.25 & 717 & 711 & & 713 \\
11.30-12.15 & & 711 & & 714 \\
12.20-1.05 & & 712 & & 714 \\
1.05-1.30 & * & * & * & * & * \\
1.30-2.15 & & 712 & & 717 & Thesis \\
2.30-3.05 & & 719 & 716 & 717 & Thesis \\
3.10-3.55 & & 719 & 716 & 719 & Thesis \\
4.00-4.45 & & & & 719 & Thesis \\
    \end{tabular}
\end{table}

\end{document} 

enter image description here enter image description here

2
  • @Bernhard The natural direction to read a tabular is from top left to bottom right, i.e. it is the row that has the focus. The interest for a reader of a time schedule will be the day, not the time slot of each day in the week. Therefore, if you change the direction of the table, you should also add some reading aid, f. ex. vertical rules (yes!), a light column (vertical) or similar.
    – Sveinung
    Jan 4, 2020 at 18:14
  • @Sveinung: Do you prefer this layout for the secod version (with a simpler code)?
    – Bernard
    Jan 4, 2020 at 21:14
2

enter image description here

With some prettifying of table header column converted to light grey with the help of

\rowcolor{gray!30}

First column converted to light grey with the help of

{\columncolor{gray!30}}l

Center column converted to red with the help of

{\columncolor{red}}c

Digits having 7 as the start are highlighted with light blue

> \makeatletter \newcommand*{\minuscellcolor}{}
> \def\minuscellcolor\ignorespaces{%   % \ignorespaces not really
> needed, because \@ifnextchar gobbles spaces  
> \@ifnextchar7{\cellcolor{blue!20}}{}% } %
> \newcolumntype{L}{>{\minuscellcolor}l}
> \newcolumntype{C}{>{\minuscellcolor}c} %
> \newcolumntype{R}{>{\minuscellcolor}r} \makeatother

Gives a neater perspective of the data visually(I think)

\documentclass{article}
\usepackage{rotating} 
\usepackage{array}
\usepackage{booktabs}  
\usepackage[table]{xcolor}
\newcolumntype{R}[1]{>{\begin{turn}{90}\begin{minipage}{#1}\scriptsize}c%
<{\end{minipage}\end{turn}}%
}
\makeatletter
\newcommand*{\minuscellcolor}{}
\def\minuscellcolor\ignorespaces{%
  % \ignorespaces not really needed, because \@ifnextchar gobbles spaces
  \@ifnextchar7{\cellcolor{blue!20}}{}%
}
% \newcolumntype{L}{>{\minuscellcolor}l}
\newcolumntype{C}{>{\minuscellcolor}c}
% \newcolumntype{R}{>{\minuscellcolor}r}
\makeatother

\begin{document}  

\begin{table}  
  \footnotesize
  \setlength\tabcolsep{3pt}
  \centering
  \begin{tabular}{>{\columncolor{gray!30}}lCCCCC>{\columncolor{red}}cCCCC}  
    \toprule  \rowcolor{gray!30}
    \multicolumn{1}{R{2cm}}{} 
      & \multicolumn{1}{R{2cm}}{9.00-9.45}
      & \multicolumn{1}{R{2cm}}{9.50-10.35}
      & \multicolumn{1}{R{2cm}}{10.40-11.25}
      & \multicolumn{1}{R{2cm}}{11.30-12.15 }
      & \multicolumn{1}{R{2cm}}{12.20-1.05 }
      & \multicolumn{1}{R{2cm}}{1.05-1.30}
      & \multicolumn{1}{R{2cm}}{1.30-2.15}
      & \multicolumn{1}{R{2cm}}{2.30-3.05}
      & \multicolumn{1}{R{2cm}}{3.10-3.55}
      & \multicolumn{1}{R{2cm}}{4.00-4.45}\\
    \cmidrule(rl){1-1} \cmidrule(rl){2-2} \cmidrule(rl){3-3} \cmidrule(rl){4-4} 
    \cmidrule(rl){5-5} \cmidrule(rl){6-6} \cmidrule(rl){7-7} \cmidrule(rl){8-8} 
    \cmidrule(rl){9-9} \cmidrule(rl){10-10}   \cmidrule(rl){11-11}   
    Sun &     & 717 & 717 &     &     & * &     &    &    &   \\  
    Mon & 715 & 715 & 711 & 711 & 712 & * & 712 & 719&719 &   \\  
    Tue &     &     &     &     &     & * &     & 716&716 &   \\  
    Wed &     & 713 & 714 & 714 & 714 & * & 717 & 717&719 &719\\  
    Thu &     &     &     &     &     & * & \#\   & \#\  & \#\ & \#\  \\
    \#\ = Thesis&&&&&&&&&&\\ 
  \bottomrule
  \end{tabular}
\end{table}
\end{document}

Courtesy @GonzaloMedina---

https://tex.stackexchange.com/a/14742/197451

and @GuilhermeZanotelli---

https://tex.stackexchange.com/a/329740/197451

2
  • 1
    You might want to replace 2cm with 1.5cm for a smaller distance between the toprule and the rotated text. Also, you might want to correct the cmidrules. Their width is not uniform.
    – leandriis
    Jan 4, 2020 at 16:42
  • why the downvote--reasons
    – js bibra
    Jan 10, 2020 at 17:18
1

Two more example, both with reduced page margins:

  • use tabularx, [table]{xcolor} packages and \small font size

enter image description here

(red lines indicate text border)

  • use sidewaystable, tabularx and [table]{xcolor} packages

enter image description here

(red lines indicate page layout)

\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage[table]{xcolor}
\usepackage{rotating}
\usepackage{tabularx}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}
    \small 
\renewcommand\arraystretch{1.2}
\rowcolors{1}{gray!30}{white}
    \begin{tabularx}{\linewidth}{| l | *{10}{>{\centering\arraybackslash}X|} }
    \cline{2-11}
\multicolumn{1}{c|}{}
    & 9.00 - 9.45 & 9.50 - 10.35 & 10.40 - 11.25 & 11.30 - 12.15 & 12.20 - 1.05
    & 1.05 - 1.30 & 1.30 - 2.15  & 2.30 - 3.05   & 3.10 - 3.55   & 4.00 - 4.45 \\
   \hline
Sun &           & 717        & 717         &             &            
    & *         &            &             &             &           \\
Mon & 715       & 715        & 711         & 711         & 712       
    & *         & 712        & 719         & 719         &           \\
Tue &           &            &             &             &            
    & *         &            & 716         & 716         &           \\
Wed &           & 711        & 713         & 714         & 714        
    & *         & 717        & 717         & 719         & 719       \\
Thu &           &            &             &             &           
    & *         & Thesis     & Thesis      & Thesis      & Thesis   \\
    \hline
    \end{tabularx}
\end{table}

\begin{sidewaystable} 
\renewcommand\arraystretch{1.2}
\setlength\tabcolsep{3pt}
\rowcolors{1}{gray!30}{white}
    \begin{tabularx}{\linewidth}{| l | *{10}{>{\centering\arraybackslash}X|} }
    \cline{2-11}
\multicolumn{1}{c|}{}
    & 9.00 - 9.45 & 9.50 - 10.35 & 10.40 - 11.25 & 11.30 - 12.15 & 12.20 - 1.05
    & 1.05 - 1.30 & 1.30 - 2.15  & 2.30 - 3.05   & 3.10 - 3.55   & 4.00 - 4.45 \\
    \hline
Sun &           & 717        & 717         &             &
    & *         &            &             &             &           \\
Mon & 715       & 715        & 711         & 711         & 712
    & *         & 712        & 719         & 719         &           \\
Tue &           &            &             &             &
    & *         &            & 716         & 716         &           \\
Wed &           & 711        & 713         & 714         & 714
    & *         & 717        & 717         & 719         & 719       \\
Thu &           &            &             &             &
    & *         & Thesis     & Thesis      & Thesis      & Thesis   \\
    \hline
    \end{tabularx}
\end{sidewaystable}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .