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}} &amp; \multicolumn{1}{|c|}{\textbf{Alphanumeric Name}} &amp; \multicolumn{1}{|c|}{\textbf{Fiber Strand Size}} (mm) &amp; 
        \multicolumn{1}{|c|}{\textbf{Color}} &amp; \multicolumn{1}{|c|}{\textbf{Stripping}} &amp; \multicolumn{1}{|c|}{\textbf{Texture}} &amp; 
        \multicolumn{1}{|c|}{\textbf{Extracted From}} \\
        \hline
        Streaky Two &amp; S2 &amp; 0.20 - 0.50 &amp; Ivory white, slightly tinged with very light brown to red or purple streak &amp; Excellent &amp; Soft &amp;
        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

  • 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. – Willie Wong Feb 01 '24 at 06: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. – Willie Wong Feb 01 '24 at 06:30
  • I see, I plan to activate hyphenation @WillieWong as it gets deactivated inside the table and I thought that the width is in the p{1in} part and the preamble is the hyphenpenalty. – Kenneth Ligutom Feb 01 '24 at 06:33
  • Stuff like these need to go into the column specification. See https://tex.stackexchange.com/questions/341592/hyphenating-text-inside-tabularx for examples on how it should be done. – Willie Wong Feb 01 '24 at 06:40
  • But it does conflict with the default settings like p and c in the column specification @WillieWong. Do I also have to add those in the column specification? – Kenneth Ligutom Feb 01 '24 at 06:44
  • 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 Feb 01 '24 at 06:59
  • do you have hyphenation turned off elsewhere? If I compile your MWE the hyphenation is active within the table without any extra work. – Willie Wong Feb 01 '24 at 07:11
  • Not really, though I set the column widths so I thought the words get hyphenated especially alphanumeric @WillieWong – Kenneth Ligutom Feb 01 '24 at 07:19
  • Man, tables in LaTeX are hard to understand @Mico. Also, this was the actual result after some fixing so yeah, that's working but still bad after I removed they hyphen penalty: https://1drv.ms/i/s!AutrB3BUl5yahacfkWs9qjXv1a1QLg?e=iC8rM7 – Kenneth Ligutom Feb 01 '24 at 07:20
  • 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 Feb 01 '24 at 07:20
  • Whoah, I thought it doesn't get hyphenated despite the settings I did for the column @Mico. – Kenneth Ligutom Feb 01 '24 at 07:23
  • So how do I hyphenate that? I tried to use \textbf{Alpha\-numeric Code} but no dice. – Kenneth Ligutom Feb 01 '24 at 07:27
  • @KennethLigutom: do you have to use the phrase "alphanumeric code"? For the table heading, wouldn't "code" just suffice? (You can explain that the column is the "alphanumeric" code in your caption.) – Willie Wong Feb 01 '24 at 07:27
  • 1
    As I wrote earlier, the cell contents cannot be hyphenated because you're using the c column type for the header cells. – Mico Feb 01 '24 at 07:29
  • Additionally, see either the first comment here: https://tex.stackexchange.com/q/592497/277964 or the answer here: https://tex.stackexchange.com/q/276154/277964 and also this question: https://tex.stackexchange.com/q/12703/277964 – cabohah Feb 01 '24 at 07:30
  • 1
    BTW: Do you know, why you are using \DeclareGraphicsExtensions{.pdf,.jpeg,.jpg,.png}? If not I would suggest to remove it, because it does not only change the search order but also remove several extensions supported by pdfTeX (or LuaTeX and even more for, e.g., XeTeX). – cabohah Feb 01 '24 at 07:49
  • Well, same reason as I stated earlier. I copied the packages and associated code since I thought I might need them at some point especially since there's formatting in my thesis paper @cabohah. – Kenneth Ligutom Feb 01 '24 at 08:02
  • 1
    Not a good reason, see my comment to your comment to Mico's answer. – cabohah Feb 01 '24 at 08:06
  • Always start with an empty preamble otherwise you end up with complicated undocumented package interactions or dead code that does nothing useful. \usepackage[utf8]{inputenc} does nothing in any latex since 2016, \usepackage{lscape} does nothing as you have loaded pdflscape. better to use txfonts for a times roman clone than mathptmx unless you need fonts in a 1990's postscript printer. why not simply \usepackage{microtype} ? you are asking for adjustments to letters to avoid stretching white space, but then have \sloppy\emergencystretch=\maxdimen allowing unlimited white space – David Carlisle Feb 01 '24 at 08:56
  • Sadly @DavidCarlisle, txfonts screws up everything in the actual document I'm working, producing a crapton of errors. The rest of the comments though where in the answer so I also removed unnecessary packages. – Kenneth Ligutom Feb 01 '24 at 09:03
  • @KennethLigutom - You may have noticed that in my answer, I suggest loading newtxtext and newtxmath insteas of mathptmx. In case you're curious about the nomenclature: the newtxtext and newtxmath packages originated with the txfonts package but have since evolved significantly. – Mico Feb 01 '24 at 11:34
  • Gotcha. I tried that one as well yet it produced a lot of errors. I applied your suggestion with the table design though @Mico. I dunno why the errors happened since I installed the missing packages as well. I'll comment it later once I uploaded the relevant screenshot in my cloud drive. – Kenneth Ligutom Feb 01 '24 at 12:00
  • Here's the link showing the errors in VSCode @Mico: 1drv.ms/i/s!AutrB3BUl5yahacwp6oUc2BZVtwHbw?e=hDnI31 – Kenneth Ligutom Feb 04 '24 at 15:55
  • @KennethLigutom - These are warning messages, not error messages, and they are utterly unrelated to the use of the newtxtext and/or newtxmath font packages. Instead, they appear to be related to unresolved cross-references. Two questions: (a) Did you verify that there are no typos in the document's \label and \ref directives? (b) Did you run LaTeX at least twice (and not delete several important aux files between runs)? – Mico Feb 04 '24 at 16:32
  • @KennethLigutom - I'm aware of the saying "there's no arguing about taste", but what exactly are you trying to achieve with arguments of \label and \ref of the the variety fig:Architectures of Mask R-CNN, Keypoint R-CNN, and FibeR-CNN? Is it within your power to come up with shorter and easier-to-manage label strings? – Mico Feb 04 '24 at 16:42
  • @Mico, these messages were related since they only appeared when I swapped the packages. The errors don't appear when I used the mathptmx package. – Kenneth Ligutom Feb 05 '24 at 08:35
  • I prefer long strings because it makes it easier for me to know which label is for which figure, especially when citing figures @Mico. – Kenneth Ligutom Feb 05 '24 at 08:37
  • @KennethLigutom - So far, you haven't exactly provided a lot of actionable information about your document structure. I've asked you two specific questions about the warning messages you've reported. Unfortunately, you've decided to respond defensively rather than try to answer my questions directly. The upshot is that I'm simply in no position to offer any kind of meaningful diagnosis of what may be going on. That said, I do happen to know that the workings of \label and \ref are completely unrelated to and separate from LaTeX's font-handling routines. – Mico Feb 05 '24 at 08:53
  • @KennethLigutom - You wrote, "The errors don't appear..." -- The messages you've reported are warning messages, not error messages. Are there maybe error messages you've encountered but not (yet) reported? – Mico Feb 05 '24 at 08:59
  • I mean, if I swap a package out for another, then it shouldn't throw all these errors. Since it should be totally unrelated. But it does happen to me. Using newtxtext and newtxmath in place of mathptmx throws all these errors. And reverting it to mathptmx package removes all these errors. I don't understand how it's not actionable @Mico. – Kenneth Ligutom Feb 05 '24 at 09:02
  • I don't have any typos. The package swap is just the one I did. And I didn't touch any related files as well @Mico. – Kenneth Ligutom Feb 05 '24 at 09:03
  • Oh I just noticed. There's an error with the amsmath and amssymb packages (Command `\Bbbk' already defined.) and removing those packages from the preamble removed the error. My bad @Mico – Kenneth Ligutom Feb 05 '24 at 09:10
  • Looks like I fixed it by swapping amsmath and amssymb with newtxtext and newtxmath in the preamble similar in your answer @Mico. – Kenneth Ligutom Feb 05 '24 at 09:12
  • @KennethLigutom - I'm glad to learn that you appear to have sorted out the main issues. – Mico Feb 05 '24 at 15:42

1 Answers1

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}

Mico
  • 506,678
  • 1
    +1 for the extra comments and the booktabs solution. – cabohah Feb 01 '24 at 07: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). – Kenneth Ligutom Feb 01 '24 at 07: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 Feb 01 '24 at 07: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. – Willie Wong Feb 01 '24 at 07: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. – Willie Wong Feb 01 '24 at 07:57
  • @WillieWong - You make some very good additional suggestions; I'll keep my fingers crossed that the OP will some or all of them on board. – Mico Feb 01 '24 at 08:17
  • Gotcha. Though that probably meant no centering of the first column but that's much better. Thank you @Mico! – Kenneth Ligutom Feb 01 '24 at 08:42