1

How do I center the last seven columns in the attached text without dropping the fixed table width or the fixed column width?

\documentclass[a4paper,12pt,oneside]{article}
\usepackage{amsmath,amssymb,bm,mathtools,amsthm}
\usepackage{graphicx}
\usepackage{float}
\usepackage{wrapfig,booktabs}
\usepackage{array}
\usepackage{multirow,dcolumn,booktabs}
\usepackage{threeparttable, tabulary, tabularx, placeins,tocloft,tocbibind}

\newcolumntype{s}{>{\hsize=1.5cm}X}

\begin{document}
\begin{threeparttable}\footnotesize
\centering
\begin{tabularx}{\textwidth}{Xsss|ssss}
\toprule
$\alpha$                &  & $ 1 $ & $ 2 $ & $ 3 $ & $ 4 $ & $ 5 $ & $ 6 $  \\
\bottomrule
\end{tabularx}
\end{threeparttable}

\end{document}
  • Can you make this into a complete compilable example? – egreg Nov 23 '14 at 16:39
  • what is s ? and do you just want c (which centres) – David Carlisle Nov 23 '14 at 16:42
  • \newcolumntype{s}{>{\hsize=1.5cm}X} (which you did not even show in the original version of the question) will entirely break tabularx. You can not use an X column to get a fixed width, the whole point of X is to get variable width. – David Carlisle Nov 23 '14 at 16:45
  • Okay. Thanks. What should I then use to get a fixed column width while perserving the fixed table width in tabularx? – Marcus Nov 23 '14 at 16:48
  • @Marcus see answer but I wouldn't use tabularx, the first column looks like it should just be l and you can use a normal tabular (or tabular*) – David Carlisle Nov 23 '14 at 16:50
2

You need p columns for fixed width, not X also there is not room for that many columns of 1.5cm so I changed it to 1.1

\documentclass[a4paper,12pt,oneside]{article}
\usepackage{amsmath,amssymb,bm,mathtools,amsthm}
\usepackage{graphicx}
\usepackage{float}
\usepackage{wrapfig,booktabs}
\usepackage{array}
\usepackage{multirow,dcolumn,booktabs}
\usepackage{threeparttable, tabulary, tabularx, placeins,tocloft,tocbibind}

\newcolumntype{s}{>{\centering\arraybackslash}p{1.1cm}}



\begin{document}
\begin{threeparttable}\footnotesize
\centering
\begin{tabularx}{\textwidth}{Xsss|ssss}
\toprule
$\alpha$                &  & $ 1 $ & $ 2 $ & $ 3 $ & $ 4 $ & $ 5 $ & $ 6 $  \\
\bottomrule
\end{tabularx}
\end{threeparttable}

\end{document}
  • Can you do this with just tabularx shoul I find more explanation in tabluarx docs? Especially the meaning of this: >{\centering\arraybackslash? – snoram Feb 26 '19 at 10:39
  • @snoram I'm not sure what you mean by "just tabularx" the above only uses tabularx, the > syntax should be described in any latex tutorial, it comes from the array package there are multiple examples in the array and tabularx doc and this site (it just inserts the centering code into each cell in that column). – David Carlisle Feb 26 '19 at 11:14
  • Sorry, I meant is what does this solution depend on apart from tabularx. I assume that, for example, I need to load the array package? – snoram Feb 26 '19 at 11:21
  • 1
    @snoram for > yes or without array just put \centering in each cell directly – David Carlisle Feb 26 '19 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.