在单个 LaTeX 表格的单元格中添加自定义左侧间距
Posted
技术标签:
【中文标题】在单个 LaTeX 表格的单元格中添加自定义左侧间距【英文标题】:Add custom left spacing in a single LaTeX table's cell 【发布时间】:2022-01-09 00:45:20 【问题描述】:我需要在表格的单元格中添加一些左侧间距。谁能帮帮我?
它遵循代码示例;我需要在标签不是粗体的第一个列的单元格中添加左间距。
\documentclassarticle
\usepackage[utf8]inputenc
\usepackagetitlesec
\usepackagebooktabs
\usepackagetabularx
\usepackagegraphics
\begindocument
\begintable[ht]
\centering
\setlength\tabcolsep2pt
\renewcommand\arraystretch1.5
\begintabular|p0.15\textwidth>\centeringp0.15\textwidth>\centeringp0.15\textwidth>\centeringp0.15\textwidth>\centeringp0.15\textwidth>\centering\arraybackslashp0.15\textwidth|
\hline
& \textbfVRE & \textbfFPE & \textbfMPE & \multicolumn2c|\textbfFull sample \\
& \textitn & \textitn & \textitn & \textitn & \textit\% \\
\hline
\textbfGender &&&&& \\
Female & 12 & 10 & 18 & 40 & 52.6 \\
Male & 10 & 13 & 13 & 36 & 47.4 \\
\hline
\textbfEducational level &&&&& \\
High School & 8 & 5 & 6 & 19 & 25.0 \\
Bachelor's Degree & 13 & 9 & 19 & 41 & 53.9 \\
Master's Degree & 1 & 8 & 6 & 15 & 19.7 \\
PhD & 0 & 1 & 0 & 1 & 1.3 \\
\hline \hline
\textbfAge &&&&& \\
Mean & 23.6 & 24.6 & 24 & \multicolumn2c|24.1 \\
Median & 23.6 & 24.6 & 24 & \multicolumn2c|24.1 \\
\hline
\endtabular
\captionParticipants demographic information
\labeltab:demographic
\endtable
提前致谢。
【问题讨论】:
因为漂亮的 MRE 而被投赞成票,包括所有包等!!! 【参考方案1】:一种可能性:您可以将\quad
(或类似的间距宏)放在这些单元格的开头:
\documentclassarticle
\usepackage[utf8]inputenc
\usepackagetitlesec
\usepackagebooktabs
\usepackagetabularx
\usepackagegraphics
\begindocument
\begintable[ht]
\centering
\setlength\tabcolsep2pt
\renewcommand\arraystretch1.5
\begintabular|p0.26\textwidth>\centeringp0.15\textwidth>\centeringp0.15\textwidth>\centeringp0.15\textwidth>\centeringp0.15\textwidth>\centering\arraybackslashp0.15\textwidth|
\hline
& \textbfVRE & \textbfFPE & \textbfMPE & \multicolumn2c|\textbfFull sample \\
& \textitn & \textitn & \textitn & \textitn & \textit\% \\
\hline
\textbfGender &&&&& \\
\quad Female & 12 & 10 & 18 & 40 & 52.6 \\
\quad Male & 10 & 13 & 13 & 36 & 47.4 \\
\hline
\textbfEducational level &&&&& \\
\quad High School & 8 & 5 & 6 & 19 & 25.0 \\
\quad Bachelor's Degree & 13 & 9 & 19 & 41 & 53.9 \\
\quad Master's Degree & 1 & 8 & 6 & 15 & 19.7 \\
\quad PhD & 0 & 1 & 0 & 1 & 1.3 \\
\hline \hline
\textbfAge &&&&& \\
\quad Mean & 23.6 & 24.6 & 24 & \multicolumn2c|24.1 \\
\quad Median & 23.6 & 24.6 & 24 & \multicolumn2c|24.1 \\
\hline
\endtabular
\captionParticipants demographic information
\labeltab:demographic
\endtable
\enddocument
与问题无关,但您的固定宽度列“浪费”了大量空间。我会改用这样的tabularx
:
\documentclassarticle
\usepackage[utf8]inputenc
\usepackagetitlesec
\usepackagebooktabs
\usepackagetabularx
\usepackagegraphics
\begindocument
\begintable[ht]
\centering
\setlength\tabcolsep10pt
\renewcommand\arraystretch1.5
\begintabularx\textwidth | X ccccc |
\hline
& \textbfVRE & \textbfFPE & \textbfMPE & \multicolumn2c|\textbfFull sample \\
& \textitn & \textitn & \textitn & \textitn & \textit\% \\
\hline
\textbfGender &&&&& \\
\quad Female & 12 & 10 & 18 & 40 & 52.6 \\
\quad Male & 10 & 13 & 13 & 36 & 47.4 \\
\hline
\textbfEducational level &&&&& \\
\quad High School & 8 & 5 & 6 & 19 & 25.0 \\
\quad Bachelor's Degree & 13 & 9 & 19 & 41 & 53.9 \\
\quad Master's Degree & 1 & 8 & 6 & 15 & 19.7 \\
\quad PhD & 0 & 1 & 0 & 1 & 1.3 \\
\hline \hline
\textbfAge &&&&& \\
\quad Mean & 23.6 & 24.6 & 24 & \multicolumn2c|24.1 \\
\quad Median & 23.6 & 24.6 & 24 & \multicolumn2c|24.1 \\
\hline
\endtabularx
\captionParticipants demographic information
\labeltab:demographic
\endtable
\enddocument
【讨论】:
以上是关于在单个 LaTeX 表格的单元格中添加自定义左侧间距的主要内容,如果未能解决你的问题,请参考以下文章