表格中的文字超出了页边距

表格中的文字超出了页边距

我很难将表格单元格内容保留在边距内。

\begin{tabular}{ @{} >{\bfseries}l @{\hspace{6ex} l }
Laboratory Skills \ & DNA Extraction, PCR, Gel electrophoresis, SDS PAGE, Restriction Digestion, Nanodrop, Microbial media preparation, culture and staining\\
Frameworks \ & Django, Flask, Spring \\
Libraries \ & Tensorflow, NLTK, scikit-learn, numpy, matplotlib, pandas \\
Miscellaneous \ & Linux, Git, REST API, \LaTeX, Content writing 
\end{tabular}

我使用了这个技巧来避免这个问题:

\begin{tabular}{ @{} >{\bfseries}l @{\hspace{4ex} l }
Laboratory Skills \ & DNA Extraction, PCR, Gel electrophoresis, SDS PAGE, Restriction Digestion, \\
 \ &  Nanodrop, Microbial media preparation, culture and staining \\
Frameworks \ & Django, Flask, Spring \\
Libraries \ & Tensorflow, NLTK, scikit-learn, numpy, matplotlib, pandas \\
Miscellaneous \ & Linux, Git, REST API, \LaTeX, Content writing 
\end{tabular}

但我不想这么做。我想要一种自动调整单元格文本的方法。

答案1

我假设您想要(a)在第二列启用自动换行以及(b)让表格占据文本块的整个宽度。

如果这些假设是正确的,那么实现格式化目标的直接方法就是采用tabularx环境。

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx}
\setlength\extrarowheight{2pt} % optional
\begin{document}

\noindent
\begin{tabularx}{\textwidth}{@{} 
     >{\bfseries}l 
     >{\raggedright\arraybackslash}X  @{}}
Laboratory Skills & DNA Extraction, PCR, Gel electrophoresis, SDS PAGE, Restriction Digestion, Nanodrop, Microbial media preparation, culture and staining\\
Frameworks & Django, Flask, Spring \\
Libraries & Tensorflow, NLTK, scikit-learn, numpy, matplotlib, pandas \\
Miscellaneous & Linux, Git, REST API, \LaTeX, Content writing 
\end{tabularx}
\end{document}

答案2

在包含长文本的表格中,有时使用 会更简单tabularytabularx因为有 L、C、R 和 J 列用于对齐内容,与tabularxX 列不同,每tabulary列可以根据内容采用不同的宽度,从而尽量缩短表格。如果结果不理想,您还可以使用列作为和p{3cm}l、r、c 列来修复列(当然,至少要保留一个 L、C、R 或 J 列,如果没有表格列,使用起来就太愚蠢了tabulary)。

还要注意,环境的长度设置tabulary不是表格的宽度,而是最大宽度。当不需要换行时,将只根据需要扩展,就像表格一样,而tabularx表格将始终扩展到该长度。

姆韦

\documentclass[11pt]{article}
\usepackage{tabulary,booktabs}
\begin{document}
\begin{tabulary}{\linewidth}{@{}>{\bfseries}lL@{}}
\toprule
Laboratory Skills & DNA Extraction, PCR, Gel electrophoresis, SDS PAGE, Restriction Digestion, Nanodrop, Microbial media preparation, culture and staining\\\addlinespace
Frameworks & Django, Flask, Spring \\\addlinespace
Libraries & Tensorflow, NLTK, scikit-learn, numpy, matplotlib, pandas \\\addlinespace
Miscellaneous  & Linux, Git, REST API, \LaTeX, Content writing \\
\bottomrule
\end{tabulary}
\end{document}

答案3

\documentclass[11pt]{article}

\begin{document}
\begin{tabular}{p{5cm}p{7cm}}
& \\
Laboratory Skills & DNA Extraction, PCR, Gel electrophoresis, SDS PAGE, Restriction Digestion, Nanodrop, Microbial media preparation, culture and staining\\
& \\
Frameworks & Django, Flask, Spring \\
& \\
Libraries & Tensorflow, NLTK, scikit-learn, numpy, matplotlib, pandas \\
& \\
Miscellaneous  & Linux, Git, REST API, \LaTeX, Content writing \\
& \\
\end{tabular}
\end{document}

% 这是一个简单的表格格式化。

相关内容