1

I tried to use multicolumn to make the first row of the table centered and the rest follows the normal paragraph rule. Here's the code snippet:

\documentclass[a4paper,12pt]{report}
\usepackage{indentfirst}
    \setlength{\parindent}{2.30em}
    
\usepackage[utf8]{inputenc}

\usepackage{pdflscape}
\usepackage{lscape}
\usepackage{booktabs, tabularx}
\usepackage{bm}
\usepackage{xfrac}

\usepackage[titles]{tocloft}

\usepackage{subfig}
\usepackage{rotating}
\usepackage{wrapfig}

\usepackage{mathptmx}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{cleveref}

\usepackage[top=1.8in, bottom=1.25in, left=1.75in, right=1.25in, headheight=1.25in]{geometry}
\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\sloppy
\microtypecontext{spacing=nonfrench}
\emergencystretch=\maxdimen

% Fonts
\usepackage{sectsty} 
    \allsectionsfont{\normalsize}

%Pagination
\usepackage{fancyhdr}
    \pagestyle{fancyplain}% <- use fancyplain instead fancy
    \fancyhf{}
    \fancyhead[R]{\thepage}
    \renewcommand{\headrulewidth}{0pt}

% Caption
\usepackage{caption}
\captionsetup{format=hang, font=normalsize, labelfont=bf, justification=justified, labelsep=period}

% Graphics
\usepackage{graphicx}
    \graphicspath{{./Figure/}}
    \DeclareGraphicsExtensions{.pdf,.jpeg,.jpg,.png}

% Spacing
\usepackage{setspace} % control linespacing
    \setstretch{1.5}
    

\clearpage

\begin{document}
    \renewcommand{\thechapter}{\Roman{chapter}}
    \chapter{Methodology}
    \renewcommand{\thechapter}{\arabic{chapter}}
    \label{ch:Methodology}
    \thispagestyle{empty}

    \begin{landscape}
        \centering
        \begin{tabularx}{\linewidth}{| p{0.75in} | p{1in} | p{0.9in} | p{2in} | p{0.8in} | p{0.6in} | p{0.8in} |}{\hyphenpenalty=20\exhyphenpenalty=20}
            \hline
            \multicolumn{1}{|c|}{\textbf{Name}} & \multicolumn{1}{|c|}{\textbf{Alphanumeric Name}} & \multicolumn{1}{|c|}{\textbf{Fiber Strand Size}} (mm) & 
            \multicolumn{1}{|c|}{\textbf{Color}} & \multicolumn{1}{|c|}{\textbf{Stripping}} & \multicolumn{1}{|c|}{\textbf{Texture}} & 
            \multicolumn{1}{|c|}{\textbf{Extracted From}} \\
            \hline
            Streaky Two & S2 & 0.20 - 0.50 & Ivory white, slightly tinged with very light brown to red or purple streak & Excellent & Soft &
            Next to the outer leafsheath \\
            \hline
        \end{tabularx}
        \label{table:Abaca Fiber Grades}
    \end{landscape}

\end{document}

However, I get the following errors in the line \end{tabularx}:

How do I remove those errors? I don't understand what the error is trying to say. Your help is much appreciated. Thank you!

enter image description here

34
  • 2
    The problem is the {\hyphenpenalty=20\exhyphenpenalty=20} you placed right after the column specification. Why do you put those there? In a tabular, \hline must start the row and cannot have anything in front of it. Commented Feb 1 at 6:29
  • 1
    Also, your \multicolumn{1}{|c|}{\textbf{Fiber Strand Size}} (mm) should probably be \multicolumn{1}{|c|}{\textbf{Fiber Strand Size} (mm)} instead; currently you are generating a spurious column. Commented Feb 1 at 6:30
  • 2
    A separate problem arises because you're imposing the c column type on the header cells, thereby disabling automatic linebreaking. As a result, the table ends up being much wider than \linewidth. Moreover, since you don't use a single instance of an X-type column, the chances that table's overall width will be equal to the target width are virtually zero.
    – Mico
    Commented Feb 1 at 6:59
  • 1
    @KennethLigutom - Since "Alphanumeric" is the first word in the cell, it'll won't get hyphenated by default, unless you use LuaLaTeX to compile your document.
    – Mico
    Commented Feb 1 at 7:20
  • 1
    As I wrote earlier, the cell contents cannot be hyphenated because you're using the c column type for the header cells.
    – Mico
    Commented Feb 1 at 7:29

1 Answer 1

2

A tabularx-type table must have at least one X-type column in order for the table's overall width to have any chance of the being equal to the target width. Also, because you're encasing each and every header cell in a \multicolumn{1}{c} wrapper, you're actually disabling line breaking in the headers cells, resulting in a table that's much too wide. My advice would be not to use the wrappers -- and not to use bold-facing either. Oh, and by all means do get rid of {\hyphenpenalty=20\exhyphenpenalty=20}.

I would further like to encourage you to give the table a more open and inviting "look", by getting rid of all vertical rules and by using well-spaced horizontal rules. Do check out the following screenshot for a comparison of the prison-cell-window and the open-and-inviting looks.

enter image description here

\documentclass[a4paper,12pt]{report}
\usepackage{indentfirst}
\setlength{\parindent}{2.30em} % that's kind of extreme
    
%\usepackage[utf8]{inputenc} % that's the default nowadays

\usepackage{pdflscape}
%\usepackage{lscape} %% don't load both lscape and pdflscape
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{tabularx}
\usepackage{bm}
\usepackage{xfrac}

\usepackage[titles]{tocloft}

\usepackage{subfig}
%%\usepackage{rotating} %% do you need this package?
\usepackage{wrapfig}

\usepackage{amsmath, amssymb} % 'amsfonts' is loaded automatically by 'amssymb'
%\usepackage{mathptmx} % mathptmx is borderline obsolete
\usepackage{newtxtext,newtxmath}

\usepackage{cleveref}

\usepackage[top=1.8in, bottom=1.25in, 
            left=1.75in, right=1.25in, 
            headheight=1.25in % this seems excessive
           ]{geometry}
\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\microtypecontext{spacing=nonfrench}
%%\sloppy %% <-- a bad idea
%%\emergencystretch=\maxdimen

% Modify styles of sectioning headers
\usepackage{sectsty} 
\allsectionsfont{\normalsize}

%Apperance of pages
\usepackage{fancyhdr}
\pagestyle{fancyplain}% <- use fancyplain instead fancy
\fancyhf{}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}

% Caption
\usepackage{caption}
\captionsetup{format=hang, 
              font=normalsize, 
              labelfont=bf, 
              justification=justified, 
              labelsep=period,
              skip=0.333\baselineskip}

% Graphics
\usepackage{graphicx}
    \graphicspath{{./Figure/}}
    \DeclareGraphicsExtensions{.pdf,.jpeg,.jpg,.png}

% Spacing
\usepackage{setspace} % control linespacing
\setstretch{1.5}

%%\clearpage % <-- not needed

%% New
\usepackage{ragged2e} % for '\RaggedRight' macro
\newcolumntype{P}[1]{>{\RaggedRight}p{#1}} % get rid of full justification, allow hyphenation
\newcolumntype{L}{>{\RaggedRight}X} % ditto
\usepackage{calc}     % for '\widthof' macro

\begin{document}
%    \renewcommand{\thechapter}{\Roman{chapter}}
%    \chapter{Methodology}
%    \label{ch:Methodology}
%    
%    \renewcommand{\thechapter}{\arabic{chapter}}
%    
%    \thispagestyle{empty}

\begin{landscape}
%%\centering % no need for this
\begin{table}
\caption{Abaca Fiber Grades}
\label{table:Abaca_Fiber_Grades}
\begin{tabularx}{\linewidth}%
   {| P{\widthof{Streaky Two}} | 
      P{\widthof{Alphanumeric}} | 
      P{\widthof{Fiber strand}} | 
      L | 
      P{\widthof{Excellent}} | 
      P{\widthof{Texture}} | 
      P{1.1in} |}
   %\hyphenpenalty=20\exhyphenpenalty=20 % huh??
   \hline
   Name & 
   Alphanumeric name & 
   Fiber strand size (mm) & 
   Color & 
   Stripping & % 'Stripping' or 'Striping'?
   Texture & 
   Extracted from \\
   \hline
   Streaky Two & 
   S2 & 
   0.20--0.50 & 
   Ivory white, slightly tinged with very light brown to red or purple streak & 
   Excellent & 
   Soft &
   Next to the outer leafsheath \\
   \hline
\end{tabularx}

\vspace*{1.5cm}
\caption{Same table, but (i) without vertical rules and (ii) with well-spaced horizontal rules}
\begin{tabularx}{\linewidth}%
 {@{} P{\widthof{Streaky Two}}  
      P{\widthof{Alphanumeric}}  
      P{\widthof{Fiber strand}}  
      L 
      P{\widthof{Excellent}}  
      P{\widthof{Texture}} 
      P{1.1in} @{}}
   %\hyphenpenalty=20\exhyphenpenalty=20 % huh?
   \toprule
   Name & 
   Alphanumeric name & 
   Fiber strand size (mm) & 
   Color & 
   Stripping & % 'Stripping' or 'Striping'?
   Texture & 
   Extracted from \\
   \midrule
   Streaky Two & 
   S2 & 
   0.20--0.50 & 
   Ivory white, slightly tinged with very light brown to red or purple streak & 
   Excellent & 
   Soft &
   Next to the outer leafsheath \\
   \bottomrule
\end{tabularx}
\end{table}
\end{landscape}

\end{document}
7
  • 1
    +1 for the extra comments and the booktabs solution.
    – cabohah
    Commented Feb 1 at 7:44
  • Thank you! The comments are appreciated as well as I just literally copied the format as well as the packages imported as well (honestly most of them). Commented Feb 1 at 7:49
  • 1
    @KennethLigutom You should get away from reflexively copying code into the document preamble as soon as possible. Instead, you should start copying only that which you not only know the purpose of, but also that you need in the specific document. Cluttered document preambles are the road to incompatibility hell.
    – cabohah
    Commented Feb 1 at 7:53
  • 1
    +1 (especially for the booktabs suggestions) Some additional items for thought: (A) use a slightly smaller font (if admissible) will help with the appearances of the paragraph in the final column. (B) Win more (horizontal) space by coming up with better column headings for "Alphanumeric Name" (maybe just "Code" suffices) and "Fiber strand size" (would "Fiber size" or "Strand size" do?) This will also allow condensing the heading to a single line, which looks nicer. Commented Feb 1 at 7:54
  • 1
    (C) Mico used P with \widthof for many of the columns, but for columns 1, 5, and 6 (and 2, 3 also if you can shorten the heading name), if the table entries are simple enough you can just use l type instead of a p type. Commented Feb 1 at 7:57

You must log in to answer this question.

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