因此,如果我制作一个正常小的表格,一切都很好。我还知道“侧向表格”的诀窍,如果我想在表格中放置太多行,当然页面的宽度最终会结束,所以我必须将其放在侧面。但是,在这种情况下,我试图构建一个 10*7 的表格。我不希望它是横向的。我假设它需要一整页的长度-高度,但这并不重要。如果我想让表格连续适合 4、5 甚至 10 页,这一定是可能的。就像在其他编辑器中一样,例如 Word 等。在我的例子中,在下面的代码中,结果结果是表格(以我想要的形式),但它太小了,单元格内的文本无法正确显示。我可以调整宽度,但我无法对长度-高度做任何事情。我弄清楚了命令,\renewcommand{\arraystretch}{8}
但它导致了不同的混乱。表格最终变大了,但是单词以及单元格中的字母总体上没有任何改变。
简单地说,正如我所看到的,桌子具有相同的空间,无论是 3x3 还是 10x7,这就是为什么如果我尝试制作一张大桌子,它只会出现在一张小桌子的空间中。
请帮我构建如链接第 5 页所示的表格: https://docplayer.net/20821469-Bacterial-classification-structure-and-function.html 这是我论文中想要包含的同一张表,这只是一个例子。我希望能够学习如何构建这样的表格。
我没有包含命令,\usepackage{}
因为我有太多命令,我不知道应该在这里包含哪些命令,但我非常确定我拥有所有必要的软件包。另外,我正在用 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}
答案1
我会选择以下
\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}
主要变化:
- 第 1、3 和 4 列宽度固定,其他列可以占用剩余空间
- 使用书标,删除所有垂直线和大部分水平线
- 将标题移至顶部并删除冗余内容
- 展开行(
\arraystretch
) - 使用较小的字体(
\small
) - 告诉 TeX 如何对第一列中的单词进行连字符连接
答案2
欢迎来到 TeX.SE!
- 您应该提供有关文档的更多信息(使用的文档类别、页面布局等),它们会影响表格布局!
- 在我看来,第一行实际上是表格标题,无论如何我把它放在表格主体中。
- 对于长表,您需要使用专用于编写长表的包之一,例如
longtable
,,等等。xltabular
tabularray
- MWE(最小工作示例)是一个小但完整、可编译的文档,其中包含您的表格(我们期望在您的问题中出现),使用
longtblr
`tabularray 包可以是:
\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}
- 表格是故意插入到文本中的,以便将其分成两页,以查看长表格的工作原理。
- 表格中使用的是无衬线字体,就像给定链接中显示的表格中使用的一样。
- 不清楚标题是否应该有标签。
- 如果你打算在某些期刊上发表你的论文,他们可能会提供模板和说明,告诉你如何准备论文。使用它们。
- 在我看来,@Teepeemm 的回答展示了表格的专业外观。这种设计
longtblr
也可以用表格轻松实现(如果您感兴趣,我可以提供)。
附录:
“专业”表的示例(没有垂直线,使用booktabs
库/包。
编辑:
- 现在被视为您的页面布局,并使用
\usepackage[english, greek]{babel}
和\usepackage[T1]{fontenc}
(与包冲突fontspec
,因此我不使用它, - 我宁愿使用字体来表示数学表达式,而不是
Times New Roman
字体(如果我没记错的话,它已经过时了) 。newtxtext
newtxmath
- MWE 我
xelatext
按照你的要求用引擎编译。结果如下所示。
\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}
答案3
不要使用adjustbox。使用p列和较小的字体大小。(最佳值取决于您的字体和您未显示的页面布局:
\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}