1

enter image description hereI would like to center the text in the middle of the respective cells for the "X" columns I have defined (last six columns). I would also like to center the table itself. This is my first time using LaTeX and I am using Overleaf. Any help is much appreciated.

\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}
7
  • Welcome to TeX SX! To centre the contents of the X columns, replace XXXXXX with *{6}{>{\centering\arraybackslash}X}.
    – Bernard
    Commented Mar 31, 2022 at 21:43
  • As to centring the table itself, you should use \begin{table}\centering\caption{Tensile Mechanical Properties} \begin{tabularx}{…} … \end{tabularx}.
    – Bernard
    Commented Mar 31, 2022 at 21:47
  • Your table has many issues: (i) why all text is in boldface? (ii) X columns are to narrow for cell contents (consequently, it overlap, prescribed table width is wider than \textwidth, consequently it spill out of right border, etc. Do you realy like to have such a table?
    – Zarko
    Commented Mar 31, 2022 at 22:12
  • Hi @Bernard, thank you. The centering seems to work fine, however, when I use \begin{tabularx}{1.00\textwidth}{|c|c|c|*{6}{>{\centering\arraybackslash}|X|}}, it appears to go all over the place. Is there a correct way to integrate this with the three rows which I already have "auto sized" with "c".
    – user267504
    Commented Apr 1, 2022 at 0:05
  • Hi @Zarko, frankly, I did not realize there existed \text{} as opposed to \textbf{}. I would like the X columns to be roughly the size of the numbers, and have the text split up vertically. I do not know the documentation for selectively sizing the columns. I originally thought that's what the number in front of \textwidth was but that's not the case. The answer is no, I don't want to have a table like this, hence why I'm reaching out for assistance
    – user267504
    Commented Apr 1, 2022 at 0:12

2 Answers 2

1
  • Table code contains errors: instead of \[mm^2\] for units in third column, you should write mm\(^2\) or mm$^2$
  • Why you have all content in boldface fonts?
  • If you like to have table wider than \textwidth, than you need locally to change it. For example by use of the changepage package
  • That text in X columns not spill-out to the right cells, their width should be wide enough
  • Your table is to wide that can be centered.

One possible redesign of your table (with minimal effort to improve its looks) can be:

\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}

enter image description here

(redlines indicate pagelayour)

0

Just as @Zarko does in his answer, I'd start by getting rid of the multitude of \textbf wrappers. I'd keep the tabularx setup, but (again as in @Zarko's answer) I'd center-set the contents of columns 4 thru 9. I'd allow automatic linebreaks, along with hanging indentation, in column 1, and I'd set the overall width to \textwidth instead of 1.25\textwidth. Finally, to give the table a more inviting and "open" look, I'd get rid of all vertical lines and the majority of horizontal lines.

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .