0

I read the first answer on this question

How to create fixed width table columns with text raggedright/centered/raggedleft?

I tried

\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{tabular}{|C{0.2cm}|C{0.5cm}|}
\hline
b & c \\
\hline
B & C \\
\hline
\end{tabular}

Result is shown below. Why for small sizes we have such an effect? How to fix it?

enter image description here

  • welcome to tex.se! the first column column width is to small for B .... try to remove \hspace{0pt} from your C column definition. – Zarko Feb 11 '18 at 10:24
  • see answers below. accept one (by clicking on check mark at top left side of answer), which help you on the best way :-). by this you will express "thank you" as is here expected (site policy). – Zarko Feb 11 '18 at 11:37

2 Answers2

1

let me elaborate ma comment below question:

  • letters B as well b are wider than 2mm ,what is defined first column width.
  • option \hspace{0pt} in your C column definition prevent cells content to spill-out to next column. consequently latex push cells content to next line where this limitation is not in force. consequently you obtain your result.

the possible cures:

  • omit\hspace{0pt} and by this allow that cell content can use \tabcolsep space on the right side of cells and if is necessary spill-out to next column
  • increase cells width. for example, if you like to have columns width ratio 2:5, (as can be concluded from your code snippet), than you can define column width as \begin{tabular}{|C{1em}|C{2.5em}|}

an example complete small document (called minimal working example: mwe) is:

\documentclass{article}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash}m{#1}}

\begin{document}
    \begin{center}
\renewcommand\arraystretch{1.2}% for more vertical space in cells
\begin{tabular}{|C{1em}|C{2.5em}|}
    \hline
b & c \\
    \hline
B & C \\
    \hline
\end{tabular}
    \end{center}
\end{document}

which gives:

enter image description here

of course you can define other column width, but they should not be small than width of letter M, i.e. 1em.

note: please in future always provide mwe, not just code snippet. with this you will help ust to help you.

Zarko
  • 296,517
0

why not using ‘tabu’ instead?

An example could be

\documentclass{article}
\usepackage{tabu}

\begin{document}

\begin{tabu} to 3cm {|X[cm]|X[2cm]|}
    \hline
    b & c \cr
    \hline
    B & C \cr
    \hline
\end{tabu}

\end{document}
Logos
  • 419