0

So, if I make a normal-small-whatever table, everything is fine. I also know the trick for a "sidewaystable" if I want too many rows in my table and of course the width of the page is ending at last, so I must put it in the side. But, in this case, I am trying to build a table that is 10*7 for example. I do not want it to be sideways. I am assuming that it will need a whole page in length-height, but that does not matter. If I want a table to fit in 4, 5 or even 10 whole pages in a row it must be possible. Like in every other editor, like Word, etc. In my case, in the following code, the resulting outcome is the table (in the form that I want it) but it is too tiny and the text inside the cells can not be seen properly. I can adjust the width, but I can not do anything at all for the length-height. I figured out the command \renewcommand{\arraystretch}{8} but it resulted in a different mess. The table eventually was bigger but the words and generally the letters in the cells did not change at all.

Simply, as I see it, the table has the same space either it is 3x3 or 10x7 and that is the reason that if I try to make a big table it just appears in the space for a small table.

Please, help me build the table as in the 5th page of the link: https://docplayer.net/20821469-Bacterial-classification-structure-and-function.html It is the same table that I want to include in my Thesis and that is only an example. I want to be able to learn how to build tables like these.

I did not include the commands \usepackage{} because I have too many and I do not know which I am suppose to include here, but I am very sure that I have all the necessary packages. Also, I am writing in XelaTeX.

\documentclass[twoside, a4paper, 11pt]{article}
\usepackage[figuresright]{rotating}
\renewcommand{\baselinestretch}{1.2}

\usepackage[top=2.5cm, left=2.5cm, right=2.5cm, bottom=2.5cm, headheight=1.25cm, footskip=1.25cm, margin=1in]{geometry}

\usepackage[T1]{fontenc} \usepackage[english, greek]{babel} \usepackage{ragged2e}

\justifying

\usepackage{fontspec} \usepackage{array} \usepackage{hyperref}

\usepackage{tabularx} \usepackage{booktabs}

\hypersetup{ colorlinks=true, linkcolor=black, citecolor=black, filecolor=black,
urlcolor=black, pdftitle={}, pdfauthor={}, pdfpagemode=FullScreen, } \urlstyle{same}

\setmainfont{Times New Roman} \usepackage{amsmath} \usepackage{amssymb}

\usepackage{alphabeta}

\usepackage{afterpage} \usepackage{esint} \usepackage{graphicx} \graphicspath{ {./Images/} } \usepackage{adjustbox} \usepackage{tabularx} \usepackage{appendix} \usepackage{listings} \usepackage{color} \usepackage{tcolorbox} \usepackage{changepage} \usepackage{subfigure} \usepackage{setspace} \usepackage{fancyhdr} \usepackage{url} \usepackage{multirow} \usepackage{cite} \usepackage{minted}

\setlength{\parindent}{0em}

\usepackage{caption} \captionsetup[figure]{name=Figure} \captionsetup[table]{name=Table}

\usepackage{float}

\usepackage{chngcntr} \counterwithin{table}{section} \counterwithin{figure}{section}

\newenvironment{dedication} {\clearpage
\thispagestyle{empty} \vspace*{\stretch{1}} \itshape
\raggedleft
} {\par \vspace{\stretch{3}} \clearpage
}

\renewenvironment{abstract} {\par\noindent\textbf{\abstractname}\ [0.4cm] \ignorespaces}

\usepackage{titlesec} \titleformat{\section} {\normalfont\LARGE\bfseries}{Chapter~\thesection :}{1em}{}

\begin{document} \begin{table}[hbt] \centering \tabcolsep=0.5cm \begin{adjustbox}{width=1.1 \textwidth} \begin{tabular}{||c|c|c|c|c|c||} \hline \multicolumn{6}{||c||}{\textbf{\textit{Gram Positive Bacteria}}} \ \hline\hline \textbf{Name} & \textbf{Morphology} & \textbf{$O_2$ requirements} & \textbf{Commensal} & \textbf{Reservoirs / Sites of Colonization, Transmission} & \textbf{Types of Infections} \ \hline Staphylococci & Cocci in grape-like clusters & facultative anaerobe & Yes & Skin, nares / endogenous, direct contact, aerosol & Soft tissue, bone, joint, endocarditis, food poisoning \ \hline Streptococci & Cocci in pairs, chains & facultative anaerobe & Some species & Oropharynx, skin / endogenous, direct contact, aerosol & Skin, pharyngitis, endocarditis, toxic shock \ \hline Pneumonococci & Diplococci, lancet shaped & facultative anaerobe & Yes / No & Oropharynx, sinus / aerosol & Pneumonia, otitis, sinusitis, meningitis \ \hline Enterococci & Cocci in pairs, chains & facultative anaerobe & Yes & GI tract / endogenous, direct contact & UTI, GI, catheter-related infections \ \hline Bacilli & Rods, spore-forming & aerobic & Yes / No & Soil, air, water, animals / aerosol, contact & Anthrax, food poisoning, catheter-related infections \ \hline Clostridia & Rods, spore formers & anaerobic & Some Species & GI tract, soil / Breach of skin, endogenous, ingestion & Tteanus, diarrhea, gas gangrene, botulism \ \hline Corynebacterium & Rods, nonspore forming & facultative anaerobe & Some species & Skin & Catheter-related infections, diphtheria \ \hline Listeria & Rods, nonspore formers & facultative anaerobe & No & Animals, food products / Ingestion & Meningitis \ \hline Actinomyces & Irregular, filamentous, form sulfur granules & anaerobic & Yes & GI tract / endogenous & Skin, soft tissue \ \hline \end{tabular} \end{adjustbox} \caption{Gram Positive Bacteria.} \label{Tab:Gram Positive Bacteria} \end{table}

\end{document}

DGuys
  • 57
  • 4
  • 5
    never scale tables like this: \begin{adjustbox}{width=1.1 \textwidth} as you see it destroys the font sizes. see https://tex.stackexchange.com/questions/332902/my-table-doesnt-fit-what-are-my-options – David Carlisle Nov 21 '23 at 21:11
  • If you're not sure what packages we need to compile, you can copy this into a new project and see what happens. In this case, we just need \usepackage{adjustbox} (although it is better to follow DavidCarlisle's advise and drop the adjustbox. – Teepeemm Nov 21 '23 at 21:14
  • @Teepeemm and David, If I drop the adjustbox then it will disappear half of my table on the right because the width would be uncontrolable and it would not be enough small to fir in the page. – DGuys Nov 21 '23 at 21:18
  • I think you are looking to specify fixed-width columns as How to create a table with fixed column widths without the use of adjustbox? – Dai Bowen Nov 21 '23 at 21:21
  • We expect that you will make MWE (Minimal Working Example}, which load only to your problem relevant package and definitions. BTW, subfigure is obsolete package, instead it use subfig or even better subcaption, it is suficient to load packages only ones, hyperref` should be loaded last in preamble .... – Zarko Nov 22 '23 at 18:33

3 Answers3

3

I would go for the following

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{table}[hbt]
\centering
\caption{Gram Positive Bacteria. \cite{Bacterial_Classification}}
\label{Tab:Gram Positive Bacteria}
\renewcommand{\arraystretch}{1.5}
\small
\begin{tabularx}{\textwidth}{ p{5em} >{\raggedright\arraybackslash}X p{5em} p{5em} >{\raggedright\arraybackslash}X >{\raggedright\arraybackslash}X }
    \toprule
    Name & Morphology & O\textsubscript{2} requirements & Commensal & Reservoirs / Sites of Colonization, Transmission & Types of Infections \\ \midrule
    Staphylo\-cocci & Cocci in grape-like clusters & facultative anaerobe & Yes & Skin, nares / endogenous, direct contact, aerosol & Soft tissue, bone, joint, endocarditis, food poisoning \\
    Strepto\-cocci & Cocci in pairs, chains & facultative anaerobe & Some species & Oropharynx, skin / endogenous, direct contact, aerosol & Skin, pharyngitis, endocarditis, toxic shock \\
    Pneumono\-cocci & Diplococci, lancet shaped & facultative anaerobe & Yes / No & Oropharynx, sinus / aerosol & Pneumonia, otitis, sinusitis, meningitis \\
    Entero\-cocci & Cocci in pairs, chains & facultative anaerobe & Yes & GI tract / endogenous, direct contact & UTI, GI, catheter-related infections \\
    Bacilli & Rods, spore-forming & aerobic & Yes / No & Soil, air, water, animals / aerosol, contact & Anthrax, food poisoning, catheter-related infections \\
    Clostridia & Rods, spore formers & anaerobic & Some Species & GI tract, soil / Breach of skin, endogenous, ingestion & Tteanus, diarrhea, gas gangrene, botulism \\
    Coryne\-bacterium & Rods, nonspore forming & facultative anaerobe & Some species & Skin & Catheter-related infections, diphtheria \\
    Listeria & Rods, nonspore formers & facultative anaerobe & No & Animals, food products / Ingestion & Meningitis \\
    Actinomyces & Irregular, filamentous, form sulfur granules & anaerobic & Yes & GI tract / endogenous & Skin, soft tissue \\\bottomrule
\end{tabularx}
\end{table}
\end{document}

Main changes:

  • columns 1, 3, and 4 are fixed width, while the others are allowed to take the rest of the space
  • use booktabs, take out all vertical rules, and most horizontal
  • move the caption to the top and remove the redundancy
  • spread out the rows (\arraystretch)
  • use a smaller font (\small)
  • tell TeX how to hyphenate the words in the first column

code output

Teepeemm
  • 6,708
  • thank you for you answer too! That is very clarifying! Am I allowed to change the structure of a table if I am taking it from a paper though? Also, if I want some vertcal rules, how can I add them? – DGuys Nov 21 '23 at 21:50
  • Finally, if I want the table to take more than one page what am I supposed to do? \renewcommand{\arraystretch}{} does not help, if I have a big value there, my table will just cut in half through the end of the page. If I have a huge table, assuming 50 rows, how will I manage it to take a few pages in a row and do not (for once again) shrink all in one page and destroy the outcome? – DGuys Nov 21 '23 at 22:15
  • The "am I allowed to change the structure of a table if I am taking it from a paper" question should be discussed with your thesis advisor, as it likely depends on the field. In mine and those adjacent to mine it is the accurate reproduction of information that matters, not the accurate reproduction of formatting. – Willie Wong Nov 22 '23 at 01:36
  • For the "multiple page" question, use longtable; it is compatible with booktabs. – Willie Wong Nov 22 '23 at 01:37
  • booktabs specifically does not work with vertical rules. The opinion of several centuries of typesetting is that they detract from conveying information. – Teepeemm Nov 22 '23 at 04:02
  • thank you for the useful informations!! But how exactly should I modify the code to include longtable in this specific structure? – DGuys Nov 22 '23 at 10:00
3

Welcome to TeX.SE!

  • You should provide more information about your document (used document class, pages layout, etc.), they influence on table layout!
  • To my opinion, the first row is actually table caption, anyway I let it in table body.
  • For long table you need to use one of packages dedicated for writing long tables, for example longtable, xltabular, tabularray etc.
  • A MWE (Minimal Working Example), a small but complete, compilable document with your table (what we expect to be in your question) using longtblr of `tabularray package can be:
\documentclass{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum}                              % for dummy text
%---------------------------------------------------------------%
\usepackage{newtxtext, newtxmath}

\usepackage{geometry} \usepackage[version=4]{mhchem} \usepackage{ragged2e} \usepackage{tabularray}

\begin{document} \lipsum[1-4]

\begin{longtblr}[

caption = {caption}, label = {longtab} ]{hlines, vlines, cells = {font=\footnotesize\sffamily}, colspec = {X[c] {3}{X[0.8,c]} {2}{X[1.5,c]}}, colsep = {2pt}, cell{1}{1} = {c=6}{}, row{1,2} = {c, font=\bfseries\itshape}, rowhead = 2} Gram Positive Bacteria \ Name & Morphology & \ce{O2} requirements & Commensal & Reservoirs / Sites of Colonization, Transmission
& Types of Infections \

Staphylococci & Cocci in grape-like clusters & facultative anaerobe & Yes & Skin, nares / endogenous, direct contact, aerosol & Soft tissue, bone, joint, endocarditis, food poisoning \

Streptococci & Cocci in pairs, chains & facultative anaerobe & Some species & Oropharynx, skin / endogenous, direct contact, aerosol & Skin, pharyngitis, endocarditis, toxic shock \ Pneumonococci & Diplococci, lancet shaped & facultative anaerobe & Yes / No & Oropharynx, sinus / aerosol & Pneumonia, otitis, sinusitis, meningitis \ Enterococci & Cocci in pairs, chains & facultative anaerobe & Yes & GI tract / endogenous, direct contact & UTI, GI, catheter-related infections \ Bacilli & Rods, spore-forming & aerobic & Yes / No & Soil, air, water, animals / aerosol, contact & Anthrax, food poisoning, catheter-related infections \ Clostridia & Rods, spore formers & anaerobic & Some Species & GI tract, soil / Breach of skin, endogenous, ingestion & Tteanus, diarrhea, gas gangrene, botulism \ Corynebacterium & Rods, nonspore forming & facultative anaerobe & Some species & Skin & Catheter-related infections, diphtheria \

Listeria & Rods, nonspore formers & facultative anaerobe & No & Animals, food products / Ingestion & Meningitis \
Actinomyces & Irregular, filamentous, form sulfur granules & anaerobic & Yes & GI tract / endogenous & Skin, soft tissue \
\end{longtblr}

\end{document}

  • Table is intentional inserted in text so, that it is split between two pages to see how long tables work.
  • In table are used sans serif fonts as they are used in table showed in given link.
  • It is not clear, if caption should have a label or not.
  • If your document is intended to be published in some journal, they probably provide template and instruction, how the article should be prepared. Use them.
  • To my opinion, professional look of table is shown in @Teepeemm answer. This design can be simple to achieve with longtblr table too (I can provide it, if you are interested).

enter image description here

Addendum:
Example of "professional" table (without vertical lines, using booktabs library/package.

Edit:

  • Now is considered your page layout, and use\usepackage[english, greek]{babel} and \usepackage[T1]{fontenc} (which is conflict with package fontspec, hence I don't use it,
  • Instead of Times New Roman font (which is obsolete, if I remember correctly) I rather use newtxtext font accompanied with newtxmath for math expressions.
  • MWE I compile with xelatext engine as you required. Result is shown below.
\documentclass[twoside, a4paper, 11pt]{article}
\usepackage[margin=2.5cm, 
            headheight=1.25cm, footskip=1.25cm]{geometry}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum}                              % for dummy text
%---------------------------------------------------------------%
\usepackage[T1]{fontenc}
\usepackage{newtxtext, newtxmath}
\usepackage[english, greek]{babel}

\usepackage[version=4]{mhchem} \usepackage{ragged2e} \usepackage{tabularray} \UseTblrLibrary{booktabs}

\begin{document} \lipsum[1-4]

\begin{longtblr}[

caption = {caption}, label = {longtab} ]{cells = {font=\footnotesize\sffamily}, colspec = {@{} X[c] {3}{X[0.8,c]} {2}{X[1.5,c]} @{}}, colsep = {2pt}, cell{1}{1} = {c=6}{}, row{1,2} = {c, font=\bfseries\itshape}, rowhead = 2} \toprule Gram Positive Bacteria \ \midrule Name & Morphology & \ce{O2} requirements & Commensal & Reservoirs / Sites of Colonization, Transmission & Types of Infections \ \midrule Staphylococci & Cocci in grape-like clusters & facultative anaerobe & Yes & Skin, nares / endogenous, direct contact, aerosol & Soft tissue, bone, joint, endocarditis, food poisoning \

Streptococci & Cocci in pairs, chains & facultative anaerobe & Some species & Oropharynx, skin / endogenous, direct contact, aerosol & Skin, pharyngitis, endocarditis, toxic shock \ Pneumonococci & Diplococci, lancet shaped & facultative anaerobe & Yes / No & Oropharynx, sinus / aerosol & Pneumonia, otitis, sinusitis, meningitis \ Enterococci & Cocci in pairs, chains & facultative anaerobe & Yes & GI tract / endogenous, direct contact & UTI, GI, catheter-related infections \ Bacilli & Rods, spore-forming & aerobic & Yes / No & Soil, air, water, animals / aerosol, contact & Anthrax, food poisoning, catheter-related infections \ Clostridia & Rods, spore formers & anaerobic & Some Species & GI tract, soil / Breach of skin, endogenous, ingestion & Tetanus, diarrhea, gas gangrene, botulism \ Corynebacterium & Rods, nonspore forming & facultative anaerobe & Some species & Skin & Catheter-related infections, diphtheria \

Listeria & Rods, nonspore formers & facultative anaerobe & No & Animals, food products / Ingestion & Meningitis \ Actinomyces & Irregular, filamentous, form sulfur granules & anaerobic & Yes & GI tract / endogenous & Skin, soft tissue \ \bottomrule \end{longtblr} \end{document}

enter image description here

Zarko
  • 296,517
  • thank you for the welcoming!!!! As far as your information given by the bullet points are concerned, they are very useful and I agree to all of them. Thank you!! But, when I copied the code I have this warning: "Package mhchem Warning: You did not specify a 'version' option for the mhchem package. Please write \usepackage[version=4]{mhchem} in your preamble (or any lower number for compatibility mode), because you might get slightly different output with the same input in future versions." – DGuys Nov 22 '23 at 10:11
  • Also, we could achieve whatever design we want with any of the packages you mentioned above? If it is not too much trouble, I would like you to provide the example of the long table TeePeemm provided, as both of your opinions agree that this is how professional tables look like. Finally, when I copied the code inside my document, table split in half and not in a continuous row. What I mean is that I had the table in the second half of page 1, on page 2 I have a text from my thesis and on the top of page 3 the other half of the table is finally continued. why? – DGuys Nov 22 '23 at 10:15
  • I did not mention before that in the code I have the text and then the table but the table appears before and after the text, somehow the text (that in the code is before the table) is inside the 2 parts of the table in the resulting outcome. – DGuys Nov 22 '23 at 10:44
  • @DGuys, you still not provide any information about your document. Please edit your code fragment and extend it to an MWE. mhchem option you can write yourself, this is not big del, my MWE compile without it just fine (now added). – Zarko Nov 22 '23 at 11:20
  • I just edited and included every package that I am using. I would really appreciate it if you could find the problem that is resulting to what I described you earlier. – DGuys Nov 22 '23 at 18:27
  • @DGuys Which problem are you referring to? If it's mchem, you'll need to make that a new question. This question is about a table, and Zarko's longtblr example works just fine with the page sizes you have in your example. – Teepeemm Nov 22 '23 at 18:50
  • no, it is not about mchem. I will say again that I use XeLaTeX (just to be sure you did not miss it). I am refereing to the problem that between my 2 pages of the same table (longtable) I have text somehow. the table goes in a different position that in the code.. Also the last example with longtblr does not compile if I use it in the same document with the others. I have all the packages I see in all of the examples, but I just can not use it in a document that has other things too. – DGuys Nov 22 '23 at 18:54
  • \UseTblrLibrary{booktabs} this package is somehow causing many errors. If I paste the last example in an empty document, everything will be fine though, but in an already existing document that has other things too, it will not run. I included every package this example has. – DGuys Nov 22 '23 at 18:56
  • @DGuys, no, it not cause any error. This library load booktabs package, so you not need to load it again. If you do so, this may cause some problems, actualy. – Zarko Nov 22 '23 at 19:09
  • 1
    XeLaTeX should not be related to text appearing in the middle of a long table. Create a new question, linking back to this one, and create a minimal working example that shows the text appearing in the middle of the code. "minimal" is important. We don't want 50 unrelated packages just because you don't want to go to the trouble of removing the package to see if the problem remains. – Teepeemm Nov 22 '23 at 19:26
2

Do not use adjustbox. Use p-columns and perhaps a smaller font size. (The best values depends on your font and your page layout which you didn't show:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{array}
\usepackage{caption}
\begin{document}
\begin{table}
\caption{caption}
\small 
\noindent\begin{tabular}{||>{\raggedright\hspace{0pt}}p{1.5cm}|>{\raggedright}p{2cm}|>{\raggedright}p{2cm}|c|>{\raggedright}p{2cm}|>{\raggedright\arraybackslash}p{3cm}||} 
    \hline
    \multicolumn{6}{||c||}{\textbf{\textit{Gram Positive Bacteria}}} \\
    \hline\hline
    \textbf{Name} & \textbf{Morphology} & \textbf{$O_2$ requirements} & \textbf{Commensal} & \textbf{Reservoirs / Sites of Colonization, Transmission} & \textbf{Types of Infections} \\ \hline
    Staphylococci & Cocci in grape-like clusters & facultative anaerobe & Yes & Skin, nares / endogenous, direct contact, aerosol & Soft tissue, bone, joint, endocarditis, food poisoning \\ \hline
    Streptococci & Cocci in pairs, chains & facultative anaerobe & Some species & Oropharynx, skin / endogenous, direct contact, aerosol & Skin, pharyngitis, endocarditis, toxic shock \\ \hline
    Pneumonococci & Diplococci, lancet shaped & facultative anaerobe & Yes / No & Oropharynx, sinus / aerosol & Pneumonia, otitis, sinusitis, meningitis \\ \hline
    Enterococci & Cocci in pairs, chains & facultative anaerobe & Yes & GI tract / endogenous, direct contact & UTI, GI, catheter-related infections \\ \hline
    Bacilli & Rods, spore-forming & aerobic & Yes / No & Soil, air, water, animals / aerosol, contact & Anthrax, food poisoning, catheter-related infections \\ \hline
    Clostridia & Rods, spore formers & anaerobic & Some Species & GI tract, soil / Breach of skin, endogenous, ingestion & Tteanus, diarrhea, gas gangrene, botulism \\ \hline
    Corynebacterium & Rods, nonspore forming & facultative anaerobe & Some species & Skin & Catheter-related infections, diphtheria \\ \hline
    Listeria & Rods, nonspore formers & facultative anaerobe & No & Animals, food products / Ingestion & Meningitis \\ \hline
    Actinomyces & Irregular, filamentous, form sulfur granules & anaerobic & Yes & GI tract / endogenous & Skin, soft tissue \\ \hline
\end{tabular}
\end{table}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • thank you very much for the clarification and that you adjusted my code!!! Can I ask you 1) if we could possibly center the text in the cells somehow? Also, 2) if you know how to bold the $O_2$ too, I tried to make this specific bold, but I could not manage to because it has the $. Finally, what is the command \small doing in our case? – DGuys Nov 21 '23 at 21:31
  • Finally, if I want the table to take more than one page what am I supposed to do? \renewcommand{\arraystretch}{} does not help, if I have a big value there, my table will just cut in half through the end of the page. If I have a huge table, assuming 50 rows, how will I manage it to take a few pages in a row and do not (for once again) shrink all in one page and destroy the outcome? – DGuys Nov 21 '23 at 22:15
  • use longtable for a long table. – Ulrike Fischer Nov 21 '23 at 23:44