1

I tried building a table with fixed column width and centered text/symbols. I used the following script.

\begin{center}
\begin{tabular}{ |p{.1cm}|p{.1cm}|p{.1cm}| } 
  \hline $\bigcirc$ & A & A \\ \hline
\end{tabular}
\end{center}

I also tried using \centering and \hspace{...} to adjust the position of the text, but it doesn't work. How do I center the text/symbols within a column of some chosen width?

4

3 Answers 3

1

If you don't need line breaks within your cells, you could use either a w column (which will suppress the overfull box warning from your content being too wide for your .1cm column width) or use W column (and make sure that your columns are wide enough for your content):

\documentclass{article}
\usepackage{mathtools}
\usepackage{array}
\begin{document}

\begin{center}
\begin{tabular}{ |w{c}{.1cm}|w{c}{.1cm}|w{c}{.1cm}| } 
  \hline $\bigcirc$ & A & A \\ \hline
\end{tabular}
\end{center}



\begin{center}
\begin{tabular}{ |W{c}{.4cm}|W{c}{.4cm}|W{c}{.4cm}| } 
  \hline $\bigcirc$ & A & A \\ \hline
\end{tabular}
\end{center}


\end{document}

enter image description here

2
  • Thank you so much for the answer! The first option seems to be working perfectly for my case!
    – samario28
    Aug 29, 2023 at 9:23
  • @samario28 You're welcome! Aug 29, 2023 at 9:24
0

If you need to employ the p ("paragraph") column type -- say, because you need automatic line-breaking within cells -- you should (a) load the array package in the preamble and (b) use the following code

\begin{center}
\begin{tabular}{ | *{3}{>{\centering\arraybackslash}p{1cm}|}  } 
  \hline 
  $\bigcirc$ & A & A \\ 
  \hline
\end{tabular}
\end{center}

to generate a tabular environment with three [3] columns with centered contents. If your document needs the centered variant of the p column type repeatedly, it's a good idea to define a bespoke new column type, as is done in the following example.


enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{array} % for '\newcolumntype' and '\arraybackslash' macros
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
\begin{center}
    \begin{tabular}{ | *{3}{P{1cm}|}  }
        \hline
        $\bigcirc$ & A & AAA AAAA AAA \\
        \hline
    \end{tabular}
\end{center}
\end{document} 
0

This crams the text into 1mm columns. Note that the width of a column from | to | is the width of the largest entry plus 2\tabcolsep.

\documentclass{article}

\begin{document}
\begin{center}
\setlength{\tabcolsep}{0pt}% you probably want to remove this
\begin{tabular}{|c|c|c|} \hline 
  \makebox[.1cm]{$\bigcirc$} & \makebox[.1cm]{A} & \makebox[.1cm]{A} \\ \hline
\end{tabular}
\end{center}
\end{document}

demo

You must log in to answer this question.

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