0

I have a longtable in which the last column is too wide. How do I fix this table?

\documentclass[12pt, a4paper, onecolumn, oneside, final]{report}
\makeatother

\usepackage{array}
\setlength\extrarowheight{4pt}

\usepackage{tabto}
\newenvironment{tabs}[1]
{\TabPositions{#1}}

\usepackage{longtable}  
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}

\usepackage{multicol}
\usepackage{multirow}
\usepackage{musicography}

\begin{document}
\begingroup
\setlength{\LTleft}{-20cm plus -1fill}
\setlength{\LTright}{\LTleft}
\begin{small}
    \begin{longtable}{|p{1cm}|p{2cm}|p{2cm}|}
        \caption{\textit{Pitch class} yang digunakan dalam penelitian}
        \label{tbl:pitchClassUsed}\\
        \hline
        {\textbf{No}} & {\textbf{No. MIDI}} & {\textbf{\textit{Pitch Class}}} \bigstrut\\
        \endfirsthead
        
        \multicolumn{3}{c}{\textbf{\tablename~\thetable} \textit{Pitch class} yang digunakan dalam penelitian (Lanjutan)}\\
        \hline
        {\textbf{No}} & {\textbf{No. MIDI}} & {\textbf{\textit{Pitch Class}}} \bigstrut\\
        \endhead
        
        \hline
        1     & 0     & \multicolumn{1}{l|}{0} \bigstrut\\
        \hline
        2     & 30    & F$\musSharp$1 / G$\flat$1 \bigstrut\\
        \hline
        3     & 31    & G1 \bigstrut\\
        \hline
        4     & 32    & G$\musSharp$1 / A$\flat$1 \bigstrut\\
        \hline
        5     & 33    & A1 \bigstrut\\
        \hline
        6     & 34    & A$\musSharp$1 / B$\flat$1 \bigstrut\\
        \hline
        7     & 35    & B1 \bigstrut\\
        \hline
        8     & 36    & C2 \bigstrut\\
        \hline
        9     & 37    & C$\musSharp$2 / D$\flat$2 \bigstrut\\
        \hline
        10    & 38    & D2 \bigstrut\\
        \hline
        11    & 39    & D$\musSharp$2 / E$\flat$2 \bigstrut\\
        \hline
        12    & 40    & E2 \bigstrut\\
        \hline
        13    & 41    & F2 \bigstrut\\
        \hline
        14    & 42    & F$\musSharp$2 / G$\flat$2 \bigstrut\\
        \hline
        15    & 43    & G2 \bigstrut\\
        \hline
        16    & 44    & G$\musSharp$2 / A$\flat$2 \bigstrut\\
        \hline
        17    & 45    & A2 \bigstrut\\
        \hline
        18    & 46    & A$\musSharp$2 / B$\flat$2 \bigstrut\\
        \hline
        19    & 47    & B2 \bigstrut\\
        \hline
        20    & 48    & C3 \bigstrut\\
        \hline
        21    & 49    & C$\musSharp$3 / D$\flat$3 \bigstrut\\
        \hline
        22    & 50    & D3 \bigstrut\\
        \hline
        23    & 51    & D$\musSharp$3 / E$\flat$3 \bigstrut\\
        \hline
        24    & 52    & E3 \bigstrut\\
        \hline
        25    & 53    & F3 \bigstrut\\
        \hline
        26    & 54    & F$\musSharp$3 / G$\flat$3 \bigstrut\\
        \hline
        27    & 55    & G3 \bigstrut\\
        \hline
        28    & 56    & G$\musSharp$3 / A$\flat$3 \bigstrut\\
        \hline
        29    & 57    & A3 \bigstrut\\
        \hline
        30    & 58    & A$\musSharp$3 / B$\flat$3 \bigstrut\\
        \hline
        31    & 59    & B3 \bigstrut\\
        \hline
        32    & 60    & C4 \bigstrut\\
        \hline
        33    & 61    & C$\musSharp$4 / D$\flat$4 \bigstrut\\
        \hline
        34    & 62    & D4 \bigstrut\\
        \hline
        35    & 63    & D$\musSharp$4 / E$\flat$4 \bigstrut\\
        \hline
        36    & 64    & E4 \bigstrut\\
        \hline
        37    & 65    & F4 \bigstrut\\
        \hline
        38    & 66    & F$\musSharp$4 / G$\flat$4 \bigstrut\\
        \hline
        39    & 67    & G4 \bigstrut\\
        \hline
        40    & 68    & G$\musSharp$4 / A$\flat$4 \bigstrut\\
        \hline
        41    & 69    & A4 \bigstrut\\
        \hline
        42    & 70    & A$\musSharp$4 / B$\flat$4 \bigstrut\\
        \hline
        43    & 71    & B4 \bigstrut\\
        \hline
        44    & 72    & C5 \bigstrut\\
        \hline
        45    & 73    & C$\musSharp$5 / D$\flat$5 \bigstrut\\
        \hline
        46    & 74    & D5 \bigstrut\\
        \hline
        47    & 76    & E5 \bigstrut\\
        \hline
        48    & 77    & F5 \bigstrut\\
        \hline
        49    & 81    & A5 \bigstrut\\
        \hline
        50    & 83    & B5 \bigstrut\\
        \hline
        51    & 85    & C$\musSharp$6 / D$\flat$6 \bigstrut\\
        \hline
    \end{longtable}%
\end{small}%
\end{document}

This is the sample output:
enter image description here

3
  • 1
    It seems to be caused by your definition of the table head for the non-first heads. The one that starts with \multicolumn{3}{c}. Once I removed this, the column had the expected size.
    – Markus G.
    Commented Apr 8, 2021 at 16:28
  • you are specifying negative fill space \setlength{\LTleft}{-20cm plus -1fill} which means that if the natural width of the table is 1cm narrower than the page, instead of supplying 1cm white soace to fill the gap it removes 1cm so making teh table 2cm too narrow. What is the intention of the -1fill ? Commented Apr 8, 2021 at 19:44
  • Please see the updated answer that addresses your follow-up question. Commented Apr 11, 2021 at 14:02

2 Answers 2

1

It is possible to repeat the caption text on each new page and not make the third column too wide, by making the caption text two lines long. The makecell package allows it.

a

\documentclass[12pt, a4paper, onecolumn, oneside, final]{report}
\makeatother

\usepackage{array}
\setlength\extrarowheight{4pt}

\usepackage{tabto}
\newenvironment{tabs}[1]
{\TabPositions{#1}}

\usepackage{longtable}  
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}

\usepackage{multicol}
\usepackage{multirow}
\usepackage{musicography}

\usepackage{bigstrut} % added <<<<<<<<<<<<
\usepackage{makecell} % added <<<<<<<<<<<<

\begin{document}
    \setlength{\LTleft}{-20cm plus -1fill}
    \setlength{\LTright}{\LTleft}
    \begin{small}
        \begin{longtable}{|p{1cm}|p{2cm}|p{4cm}|}
            \caption{\textit{Pitch class} yang digunakan dalam penelitian}
            \label{tbl:pitchClassUsed}\\
            \hline
            {\textbf{No}} & {\textbf{No. MIDI}} & {\textbf{\textit{Pitch Class}}} \bigstrut\\
            \endfirsthead
    % next line changed <<<<<<<<<<<<                    
            \multicolumn{3}{c}{\makecell{\textbf{\tablename~\thetable} \textit{Pitch class} yang digunakan \\ dalam penelitian (Lanjutan)}}\\[12pt]     % changed <<<<<<<<<<<<
            \hline
            {\textbf{No}} & {\textbf{No. MIDI}} & {\textbf{\textit{Pitch Class}}} \bigstrut\\
            \endhead
            
            \hline
            1     & 0     & \multicolumn{1}{l|}{0} \bigstrut\\
            \hline
            2     & 30    & F$\musSharp$1 / G$\flat$1 \bigstrut\\
            \hline
            3     & 31    & G1 \bigstrut\\
            \hline
            4     & 32    & G$\musSharp$1 / A$\flat$1 \bigstrut\\
            \hline
            5     & 33    & A1 \bigstrut\\
            \hline
            6     & 34    & A$\musSharp$1 / B$\flat$1 \bigstrut\\
            \hline
            7     & 35    & B1 \bigstrut\\
            \hline
            8     & 36    & C2 \bigstrut\\
            \hline
            9     & 37    & C$\musSharp$2 / D$\flat$2 \bigstrut\\
            \hline
            10    & 38    & D2 \bigstrut\\
            \hline
            11    & 39    & D$\musSharp$2 / E$\flat$2 \bigstrut\\
            \hline
            12    & 40    & E2 \bigstrut\\
            \hline
            13    & 41    & F2 \bigstrut\\
            \hline
            14    & 42    & F$\musSharp$2 / G$\flat$2 \bigstrut\\
            \hline
            15    & 43    & G2 \bigstrut\\
            \hline
            16    & 44    & G$\musSharp$2 / A$\flat$2 \bigstrut\\
            \hline
            17    & 45    & A2 \bigstrut\\
            \hline
            18    & 46    & A$\musSharp$2 / B$\flat$2 \bigstrut\\
            \hline
            19    & 47    & B2 \bigstrut\\
            \hline
            20    & 48    & C3 \bigstrut\\
            \hline
            21    & 49    & C$\musSharp$3 / D$\flat$3 \bigstrut\\
            \hline
            22    & 50    & D3 \bigstrut\\
            \hline
            23    & 51    & D$\musSharp$3 / E$\flat$3 \bigstrut\\
            \hline
            24    & 52    & E3 \bigstrut\\
            \hline
            25    & 53    & F3 \bigstrut\\
            \hline
            26    & 54    & F$\musSharp$3 / G$\flat$3 \bigstrut\\
            \hline
            27    & 55    & G3 \bigstrut\\
            \hline
            28    & 56    & G$\musSharp$3 / A$\flat$3 \bigstrut\\
            \hline
            29    & 57    & A3 \bigstrut\\
            \hline
            30    & 58    & A$\musSharp$3 / B$\flat$3 \bigstrut\\
            \hline
            31    & 59    & B3 \bigstrut\\
            \hline
            32    & 60    & C4 \bigstrut\\
            \hline
            33    & 61    & C$\musSharp$4 / D$\flat$4 \bigstrut\\
            \hline
            34    & 62    & D4 \bigstrut\\
            \hline
            35    & 63    & D$\musSharp$4 / E$\flat$4 \bigstrut\\
            \hline
            36    & 64    & E4 \bigstrut\\
            \hline
            37    & 65    & F4 \bigstrut\\
            \hline
            38    & 66    & F$\musSharp$4 / G$\flat$4 \bigstrut\\
            \hline
            39    & 67    & G4 \bigstrut\\
            \hline
            40    & 68    & G$\musSharp$4 / A$\flat$4 \bigstrut\\
            \hline
            41    & 69    & A4 \bigstrut\\
            \hline
            42    & 70    & A$\musSharp$4 / B$\flat$4 \bigstrut\\
            \hline
            43    & 71    & B4 \bigstrut\\
            \hline
            44    & 72    & C5 \bigstrut\\
            \hline
            45    & 73    & C$\musSharp$5 / D$\flat$5 \bigstrut\\
            \hline
            46    & 74    & D5 \bigstrut\\
            \hline
            47    & 76    & E5 \bigstrut\\
            \hline
            48    & 77    & F5 \bigstrut\\
            \hline
            49    & 81    & A5 \bigstrut\\
            \hline
            50    & 83    & B5 \bigstrut\\
            \hline
            51    & 85    & C$\musSharp$6 / D$\flat$6 \bigstrut\\
            \hline
        \end{longtable}%
    \end{small}%
\end{document}

Note (not related with the question)

You can improve the look of the table by centering the first two columns.

Add \newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

and use \begin{longtable}{|C{1cm}|C{2cm}|p{4cm}|}

b

UPDATE

What is causing the observed widening of the last column is the text that is intended to go at the top of the table on the next page.

It is not a "caption", but a multi-column cell in the table, wider than the aggregate width of the three columns.

Instead of repeating the caption text, as if it were the beginning of the table, it is better to use it to link this part of the table with the previous one. A table footer is also recommended to alert the reader that this is not the end of the table.

The third column can now be narrower.

z

Start the longtable this way

        \begin{longtable}{|C{1cm}|C{2cm}|p{2.5cm}|}
            \caption{\textit{Pitch class} yang digunakan dalam penelitian}
            \label{tbl:pitchClassUsed}\\
            \hline
            {\textbf{No}} & {\textbf{No. MIDI}} & {\textbf{\textit{Pitch Class}}} \bigstrut\\
            \endfirsthead
            % next lines changed <<<<<<<<<<<<           
            \multicolumn{3}{c}{\textbf{\tablename~\thetable} \, \textit{\dots{} from the previous page}} \bigstrut\\                
            \hline
            {\textbf{No}} & {\textbf{No. MIDI}} & {\textbf{\textit{Pitch Class}}} \bigstrut\\
            \endhead
            \multicolumn{3}{r}{\textit{continued on the next page \dots{} }}
            \endfoot                
            \endlastfoot
            %% ***************************************
            \hline
            1     & 0     & \multicolumn{1}{l|}{0} \bigstrut\\
      ...........
3
  • Thanks! Out of this question, I am now curious, is there any way in LaTeX in which I can separate table caption and its data? Because I think that caption is making my table (not just this one) last column longer than it is defined. Commented Apr 11, 2021 at 8:41
  • 1
    @Dionisius Pratama Please see the updated answer that addresses this follow-up question. Commented Apr 11, 2021 at 14:03
  • I've seen the updated answer. Thank you again for answering. I'll try to implement this code tomorrow. Commented Apr 11, 2021 at 16:37
1

You could entirely avoid the issue by making sure the whole table fits onto a single page. The following MWE shows to approaches resulting in table that both easily fit onto a single page, even without reducing the font size:

enter image description here

\documentclass[12pt, a4paper, onecolumn, oneside, final]{report}

\usepackage{musicography}
\usepackage{makecell}
\setcellgapes{5pt}

\usepackage{booktabs}
\begin{document}
\begin{table}
\makegapedcells
    \caption{\textit{Pitch class} yang digunakan dalam penelitian}
    \label{tbl:pitchClassUsed}
    \begin{tabular}{|l|l|l| l|l|l|}
        \hline
        {\textbf{No}} & {\textbf{No. MIDI}} & {\textbf{\textit{Pitch Class}}} & {\textbf{No}} & {\textbf{No. MIDI}} & {\textbf{\textit{Pitch Class}}} \\
    \hline

        1     & 0     & \multicolumn{1}{l|}{0}    & 27    & 55    & G3 \\                         
        \hline                                                                                    
        2     & 30    & F$\musSharp$1 / G$\flat$1 & 28    & 56    & G$\musSharp$3 / A$\flat$3 \\  
        \hline                                                                                    
        3     & 31    & G1                        & 29    & 57    & A3 \\                         
        \hline                                                                                    
        4     & 32    & G$\musSharp$1 / A$\flat$1 & 30    & 58    & A$\musSharp$3 / B$\flat$3 \\  
        \hline                                                                                    
        5     & 33    & A1                        & 31    & 59    & B3 \\                         
        \hline                                                                                    
        6     & 34    & A$\musSharp$1 / B$\flat$1 & 32    & 60    & C4 \\                         
        \hline                                                                                    
        7     & 35    & B1                        & 33    & 61    & C$\musSharp$4 / D$\flat$4 \\  
        \hline                                                                                    
        8     & 36    & C2                        & 34    & 62    & D4 \\                         
        \hline                                                                                    
        9     & 37    & C$\musSharp$2 / D$\flat$2 & 35    & 63    & D$\musSharp$4 / E$\flat$4 \\  
        \hline                                                                                    
        10    & 38    & D2                        & 36    & 64    & E4 \\                         
        \hline                                                                                    
        11    & 39    & D$\musSharp$2 / E$\flat$2 & 37    & 65    & F4 \\                         
        \hline                                                                                    
        12    & 40    & E2                        & 38    & 66    & F$\musSharp$4 / G$\flat$4 \\  
        \hline                                                                                    
        13    & 41    & F2                        & 39    & 67    & G4 \\                         
        \hline                                                                                    
        14    & 42    & F$\musSharp$2 / G$\flat$2 & 40    & 68    & G$\musSharp$4 / A$\flat$4 \\  
        \hline                                                                                    
        15    & 43    & G2                        & 41    & 69    & A4 \\                         
        \hline                                                                                    
        16    & 44    & G$\musSharp$2 / A$\flat$2 & 42    & 70    & A$\musSharp$4 / B$\flat$4 \\  
        \hline                                                                                    
        17    & 45    & A2                        & 43    & 71    & B4 \\                         
        \hline                                                                                    
        18    & 46    & A$\musSharp$2 / B$\flat$2 & 44    & 72    & C5 \\                         
        \hline                                                                                    
        19    & 47    & B2                        & 45    & 73    & C$\musSharp$5 / D$\flat$5 \\  
        \hline                                                                                    
        20    & 48    & C3                        & 46    & 74    & D5 \\                         
        \hline                                                                                    
        21    & 49    & C$\musSharp$3 / D$\flat$3 & 47    & 76    & E5 \\                         
        \hline                                                                                    
        22    & 50    & D3                        & 48    & 77    & F5 \\                         
        \hline                                                                                    
        23    & 51    & D$\musSharp$3 / E$\flat$3 & 49    & 81    & A5 \\                         
        \hline                                                                                    
        24    & 52    & E3                        & 50    & 83    & B5 \\                         
        \hline                                                                                    
        25    & 53    & F3                        & 51    & 85    & C$\musSharp$6 / D$\flat$6 \\  
        \hline
        26    & 54    & F$\musSharp$3 / G$\flat$3 \\
        \cline{1-3}
    \end{tabular}
\end{table}%

\begin{table}
    \caption{\textit{Pitch class} yang digunakan dalam penelitian}
    \label{tbl:pitchClassUsed}
    \begin{tabular}{@{}rcl@{\qquad}rcl @{\qquad}rcl@{}}
        \toprule
        \thead{No} & \thead{No.\\ MIDI} & \thead{Pitch Class} & \thead{No} & \thead{No.\\ MIDI} & \thead{Pitch Class} & \thead{No} & \thead{No.\\ MIDI} & \thead{Pitch Class} \\
    \cmidrule(r{2em}){1-3} \cmidrule(r{2em}){4-6} \cmidrule{7-9}
        1     & 0     & \multicolumn{1}{l}{0}     & 18    & 46    & A$\musSharp$2 / B$\flat$2 & 35    & 63    & D$\musSharp$4 / E$\flat$4  \\                                                                                                            
        2     & 30    & F$\musSharp$1 / G$\flat$1 & 19    & 47    & B2                        & 36    & 64    & E4                         \\                                                                                      
        3     & 31    & G1                        & 20    & 48    & C3                        & 37    & 65    & F4                         \\                                                                                                            
        4     & 32    & G$\musSharp$1 / A$\flat$1 & 21    & 49    & C$\musSharp$3 / D$\flat$3 & 38    & 66    & F$\musSharp$4 / G$\flat$4  \\                                                                                              
        5     & 33    & A1                        & 22    & 50    & D3                        & 39    & 67    & G4                         \\ \addlinespace                                    
        6     & 34    & A$\musSharp$1 / B$\flat$1 & 23    & 51    & D$\musSharp$3 / E$\flat$3 & 40    & 68    & G$\musSharp$4 / A$\flat$4  \\                                                                                                                     
        7     & 35    & B1                        & 24    & 52    & E3                        & 41    & 69    & A4                         \\                                                                                              
        8     & 36    & C2                        & 25    & 53    & F3                        & 42    & 70    & A$\musSharp$4 / B$\flat$4  \\                                                                                                                     
        9     & 37    & C$\musSharp$2 / D$\flat$2 & 26    & 54    & F$\musSharp$3 / G$\flat$3 & 43    & 71    & B4                         \\                                                                                              
        10    & 38    & D2                        & 27    & 55    & G3                        & 44    & 72    & C5                         \\ \addlinespace                                                                                                                     
        11    & 39    & D$\musSharp$2 / E$\flat$2 & 28    & 56    & G$\musSharp$3 / A$\flat$3 & 45    & 73    & C$\musSharp$5 / D$\flat$5  \\                                                                                                                   
        12    & 40    & E2                        & 29    & 57    & A3                        & 46    & 74    & D5                         \\                                                                 
        13    & 41    & F2                        & 30    & 58    & A$\musSharp$3 / B$\flat$3 & 47    & 76    & E5                         \\                                                                                           
        14    & 42    & F$\musSharp$2 / G$\flat$2 & 31    & 59    & B3                        & 48    & 77    & F5                         \\                                                                   
        15    & 43    & G2                        & 32    & 60    & C4                        & 49    & 81    & A5                         \\ \addlinespace                                                                                         
        16    & 44    & G$\musSharp$2 / A$\flat$2 & 33    & 61    & C$\musSharp$4 / D$\flat$4 & 50    & 83    & B5                         \\                                                       
        17    & 45    & A2                        & 34    & 62    & D4                        & 51    & 85    & C$\musSharp$6 / D$\flat$6  \\                                                                                                   
        \bottomrule
    \end{tabular}
\end{table}%
\end{document}
1
  • This is exactly what I'm just about to ask just now 😂. Thank you for the insight! I'll try to implement this to some of my other tables. Commented Apr 11, 2021 at 16:38

You must log in to answer this question.

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