我想将文本置于我定义的“X”列(最后六列)相应单元格的中间。我还想将表格本身置于中间。这是我第一次使用 LaTeX,我正在使用 Overleaf。任何帮助都非常感谢。
\documentclass{article}
% Language setting
% Replace `english' with e.g. `spanish' to change the document language
\usepackage[english]
\usepackage{biblatex}
\usepackage[nomarkers,figuresonly]{endfloat}
\usepackage{gensymb} %package for adding degree symbol
% Set page size and margins
% Replace `letterpaper' with `a4paper' for UK/EU standard size
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}
% Useful packages
\usepackage{textgreek}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{ragged2e}
\usepackage{tabularx}
\begin{document}
\begin{center}
\caption{Table 1 - Tensile Mechanical Properties}
\begin{tabularx}{1.25\textwidth}{|c|c|c|X|X|X|X|X|X|}
\hline
\multicolumn{3}{|c|}{\textbf{Measurement or Property}} &\multicolumn{6}{c|}{\textbf{Material}} \\ \hline
\textbf{Quantity} & \textbf{Symbol} & \textbf{Units} & \textbf{CI} & \textbf{1045CR} & \textbf{1045NM} & \textbf{2024 AL} & \textbf{304 SS} & \textbf{PMMA} \\ \hline
\multicolumn{9}{|c|}{\textbf{Initial Data}}\\ \hline
\textbf{Diameter}&\textbf{d0}&\textbf{mm} & \textbf{7.14} & \textbf{7.19}& \textbf{7.06}& \textbf{7.1}& \textbf{7.13}& \textbf{8.00}\\ \hline
\textbf{Cross-sect Area}&\textbf{A0}&\textbf{\[mm^2\]} & \textbf{40.04} & \textbf{40.6}& \textbf{39.1}& \textbf{39.6}& \textbf{39.9}& \textbf{50.3}\\ \hline
\multicolumn{9}{|c|}{\textbf{Strength}} \\ \hline
\textbf{Yield Load}&\textbf{\(P_{y}\)}&\textbf{kN} & \textbf{} & \textbf{19.53}& \textbf{19.84}& \textbf{13.96}& \textbf{9.11}& \textbf{}\\ \hline
\textbf{Max Load}&\textbf{\(P_{max}\)}&\textbf{kN} & \textbf{13.16} & \textbf{32.47}& \textbf{28.41}& \textbf{19.00}& \textbf{24.42}& \textbf{3.67}\\ \hline
\textbf{Shape Changes during deformation}&\textbf{-}&\textbf{-} & \textbf{None} & \textbf{Slight Necking}& \textbf{Necking}& \textbf{Very slight necking}& \textbf{Extreme Necking}& \textbf{None}\\ \hline
\textbf{Description of Fracture Surface}&\textbf{-}&\textbf{-} & \textbf{Flat, Graphite flakes} & \textbf{Cup and Cone}& \textbf{Cup and Cone}& \textbf{Shear lips and orange peel}& \textbf{Extreme Cup and Cone}& \textbf{Flat crack init. on edge}\\ \hline
\multicolumn{9}{|c|}{\textbf{Hardness}} \\ \hline
\textbf{Rockwell Hardness}&\textbf{HRB}&\textbf{-} & \textbf{100.9} & \textbf{95.5}& \textbf{89.4}& \textbf{75.4}& \textbf{71.7}& \textbf{-}\\ \hline
\multicolumn{9}{|c|}{\textbf{Ductility}} \\ \hline
\textbf{Gage Length}&\textbf{\(l_{0}\)}&\textbf{mm} & \multicolumn{6}{|c|}{\textbf{25.4}}\\ \hline
\textbf{Percent Elongation}&\textbf{\%EL}&\textbf{-} & \textbf{1.05} & \textbf{14.6}& \textbf{27.4}& \textbf{19.9}& \textbf{78.2}& \textbf{3.00}\\ \hline
\textbf{Final Diameter}&\textbf{\(d_{f}\)}&\textbf{mm} & \textbf{7.09} & \textbf{5.74}& \textbf{4.58}& \textbf{6.19}& \textbf{3.06}& \textbf{7.96}\\ \hline
\textbf{Final Area}&\textbf{\(A_{f}\)}&\textbf{\[mm^2\]} & \textbf{39.5} & \textbf{25.9}& \textbf{16.5}& \textbf{30.1}& \textbf{7.35}& \textbf{49.8}\\ \hline
\textbf{Percent Reduction of area}&\textbf{\%RA}&\textbf{-} & \textbf{1.40} & \textbf{36.3}& \textbf{57.9}& \textbf{24.0}& \textbf{81.6}& \textbf{1.00}\\ \hline
\multicolumn{9}{|c|}{\textbf{Mechanical Properties Derived from stress-strain diagram}}\\ \hline
\textbf{Young's Modulus}&\textbf{E}&\textbf{GPa} & \textbf{103} & \textbf{194}& \textbf{198}& \textbf{72}& \textbf{204}& \textbf{4.15}\\ \hline
\textbf{Yield Strength}&\textbf{\(\sigma_y\)}&\textbf{MPa} & \textbf{108} & \textbf{474}& \textbf{498}& \textbf{352}& \textbf{229}& \textbf{-}\\ \hline
\textbf{Ultimate Strength}&\textbf{\(\sigma_u\)}&\textbf{MPa} & \textbf{323} & \textbf{798}& \textbf{719}& \textbf{478}& \textbf{612}& \textbf{75}\\ \hline
%\label{}
\end{tabularx}
\end{center}
\end{document}
\end{document}
答案1
- 表格代码包含错误:
\[mm^2\]
第三列中的单位不应为,而应为mm\(^2\)
或mm$^2$
- 为什么所有内容都是
boldface
字体? - 如果你希望表格宽度大于
\textwidth
,那么你需要在本地进行更改。例如,通过使用changepage
包 - 列中的文本
X
不会溢出到右侧单元格,其宽度应该足够宽 - 您的桌子太宽,无法居中。
对你的表格进行一种可能的重新设计(尽量少用力改善其外观)可以是:
\documentclass{article}
\usepackage[letterpaper,
vmargin=2cm, hmargin=3cm,
marginparwidth=1.75cm]{geometry}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{ragged2e}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage[strict]{changepage}
\begin{document}
\begin{table}[ht]
\begin{adjustwidth}{}{-\dimexpr\marginparwidth+\marginparsep} % <--- new
\caption{Table 1 - Tensile Mechanical Properties}
\label{tab:??}
\setlength\tabcolsep{3pt} % <--- new
\small % <--- new
\begin{tabularx}{\linewidth}{|>{\centering}p{0.2\linewidth}|c|c|C|C|C|C|C|C|} % <--- changed
\hline
\multicolumn{3}{|c|}{Measurement or Property} &\multicolumn{6}{c|}{{Material}} \\ \hline
Quantity & Symbol & Units & CI & 1045CR & 1045NM & 2024 AL & 304 SS & PMMA \\ \hline
\multicolumn{9}{|c|}{Initial Data}\\ \hline
Diameter&d0& mm & 7.14 & 7.19& 7.06& 7.1& 7.13& 8.00\\ \hline
Cross-sect Area&A0& mm$^2$ & 40.04 & 40.6& 39.1& 39.6& 39.9& 50.3\\ \hline
\multicolumn{9}{|c|}{Strength} \\ \hline
Yield Load&\(P_y\)& kN & & 19.53& 19.84& 13.96& 9.11& \\ \hline
Max Load&\(P_max\)& kN & 13.16 & 32.47& 28.41& 19.00& 24.42& 3.67\\ \hline
Shape Changes during deformation&-&- & None & Slight Necking& Necking& Very slight necking& Extreme Necking& None\\ \hline
Description of Fracture Surface&-&- & Flat, Graphite flakes & Cup and Cone& Cup and Cone& Shear lips and orange peel& Extreme Cup and Cone& Flat crack init. on edge\\ \hline
\multicolumn{9}{|c|}{Hardness} \\ \hline
Rockwell Hardness&HRB&- & 100.9 & 95.5& 89.4& 75.4& 71.7& -\\ \hline
\multicolumn{9}{|c|}{Ductility} \\ \hline
Gage Length&\(l_0\)&mm & \multicolumn{6}{|c|}{25.4}\\ \hline
Percent Elongation&\%EL&- & 1.05 & 14.6& 27.4& 19.9& 78.2& 3.00\\ \hline
Final Diameter&\(d_f\)&mm & 7.09 & 5.74& 4.58& 6.19& 3.06& 7.96\\ \hline
Final Area&\(A_f\)&mm$^2$ & 39.5 & 25.9& 16.5& 30.1& 7.35& 49.8\\ \hline
Percent Reduction of area&\%RA&- & 1.40 & 36.3& 57.9& 24.0& 81.6& 1.00\\ \hline
\multicolumn{9}{|c|}{Mechanical Properties Derived from stress-strain diagram}\\ \hline
Young's Modulus&E&GPa & 103 & 194& 198& 72& 204& 4.15\\ \hline
Yield Strength&\(\sigma_y\)&MPa & 108 & 474& 498& 352& 229& -\\ \hline
Ultimate Strength&\(\sigma_u\)&MPa & 323 & 798& 719& 478& 612& 75\\ \hline
%\label{}
\end{tabularx}
\end{adjustwidth}
\end{table}
\end{document}
(红线表示页面布局)
答案2
正如@Zarko 所做的那样他的回答,我首先要摆脱大量的\textbf
包装器。我会保留设置tabularx
,但(再次像@Zarko的回答一样)我会将第 4 列到第 9 列的内容居中设置。我会在第 1 列中允许自动换行以及悬挂缩进,并将整体宽度设置为\textwidth
而不是1.25\textwidth
。最后,为了让表格看起来更吸引人、更“开放”,我会去掉所有垂直线和大部分水平线。
\documentclass{article}
% Language setting
% Replace `english' with e.g. `spanish' to change the document language
%\usepackage[english]% % <-- you're missing the main argument
\usepackage[english]{babel}
%\usepackage{biblatex}
\usepackage[nomarkers,figuresonly]{endfloat}
\usepackage{gensymb} %package for adding degree symbol
% Set page size and margins
% Replace `letterpaper' with `a4paper' for UK/EU standard size
\usepackage[letterpaper,vmargin=2cm,hmargin=3cm,marginparwidth=1.75cm]{geometry}
% Useful packages
\usepackage{booktabs}
\usepackage{textgreek}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{ragged2e}
\usepackage{tabularx}
\newcolumntype{C}{>{\Centering}X}
\begin{document}
\begin{table}
\setlength\tabcolsep{4pt} % default: 6pt
\caption{Table 1 -- Tensile Mechanical Properties}
\begin{tabularx}{1\textwidth}{@{}
>{\RaggedRight\hangafter=1\hangindent=1em}p{2.75cm}
cc
*{6}{C} @{}}
\toprule
\multicolumn{3}{@{}c}{Measurement or property} &
\multicolumn{6}{c@{}}{Material} \\
\cmidrule(r){1-3} \cmidrule(l){4-9}
Quantity & Symbol & Units & CI & 1045CR & 1045NM & \mbox{2024 AL} & 304 SS & PMMA \\
\midrule
\addlinespace
\multicolumn{9}{@{}l}{Initial Data}\\
\midrule
Diameter & d0 & mm & 7.14 & 7.19 & 7.06 & 7.1 & 7.13 & 8.00 \\
Cross-sect area & A0 & mm\rlap{${}^2$} & 40.04 & 40.6 & 39.1 & 39.6 & 39.9 & 50.3 \\ \midrule
\addlinespace
\multicolumn{9}{@{}l}{Strength} \\
\midrule
Yield load & \(P_{y}\) & kN & & 19.53 & 19.84 & 13.96 & 9.11 & \\
Max load & \(P_{\max}\) & kN & 13.16 & 32.47 & 28.41 & 19.00 & 24.42 & 3.67 \\
\addlinespace
Shape changes during deformation & -- & -- & None & Slight necking & Necking & Very slight necking & Extreme necking & None \\
\addlinespace
Description of fracture surface & -- & -- & Flat, graphite flakes & Cup and cone & Cup and cone & Shear lips and orange peel & Extreme cup and cone & Flat crack init.\ on edge \\
\midrule
\addlinespace
\multicolumn{9}{@{}l}{Hardness} \\
\midrule
Rockwell hardness & HRB & -- & 100.9 & 95.5 & 89.4 & 75.4 & 71.7 & -\\
\midrule
\addlinespace
\multicolumn{9}{@{}l}{Ductility} \\
\midrule
Gage length & \(l_{0}\) & mm & \multicolumn{6}{c@{}}{25.4}\\
Percent elongation & \%EL & -- & 1.05 & 14.6 & 27.4 & 19.9 & 78.2 & 3.00 \\
Final diameter & \(d_{f}\) & mm & 7.09 & 5.74 & 4.58 & 6.19 & 3.06 & 7.96 \\
Final area & \(A_{f}\) & mm\rlap{${}^2$} & 39.5 & 25.9 & 16.5 & 30.1 & 7.35 & 49.8 \\
Percent reduction of area & \%RA & -- & 1.40 & 36.3 & 57.9 & 24.0 & 81.6 & 1.00 \\
\midrule
\addlinespace
\multicolumn{9}{@{}l}{Mechanical properties derived from stress-strain diagram} \\
\midrule
Young's modulus & E & GPa & 103 & 194 & 198 & 72 & 204 & 4.15 \\
Yield strength & \(\sigma_y\) & MPa & 108 & 474 & 498 & 352 & 229 & -- \\
Ultimate strength & \(\sigma_u\) & MPa & 323 & 798 & 719 & 478 & 612 & 75 \\ \bottomrule
%\label{}
\end{tabularx}
\end{table}
\end{document}