1

How to achieve this alignment? enter image description here Instead:

\documentclass{article}
\usepackage{array, tabu} 
\begin{document}
\begin{table}[h]
\begin{tabu} to 1.0\textwidth { |X[c]|X[c]| }
\hline
$ N_{1} $ & $ (0: 1] $ \\[3cm]  \hline
\end{tabu}
\end{table}
\end{document}

enter image description here

  • looks ok to me. – novice Jun 10 '16 at 19:36
  • 1
    I don't know tabu. However, it's easy to do with a tabularx environment and the cellspace package. – Bernard Jun 10 '16 at 19:38
  • Welcome to TeX.SE. Please extend your code snipped to complete small document, which we can copy and compile in own computers. As it is is not possible to say anything. With my test I can't reproduce your problem. – Zarko Jun 10 '16 at 21:03
  • Thank you for your early reply and for the greetings! Expanded text code to a simple compilation. The result is different from the picture but the essence remains the same. Alignment strictly on the cell center. P.S. sorry for my English. – Dmitry Jun 10 '16 at 21:57
2

Try the following dirty trick:

\documentclass{article}
\usepackage{array, tabu}
\begin{document}
\begin{table}[h]

\begin{tabu} to 1.0\textwidth { |X[c,$] | X[c,$]m{0pt}|}
\hline
N_{1}  &  (0: 1]  & \\[3cm]  \hline
\end{tabu}
\end{table}
\end{document}

enter image description here

It is not clear, why you need so strange table design. And use of tabu package is tricky. It is not maintained and contain bugs ...

Addendum: Vertical centering of cell content is not simple task. For this purpose is added a fake column m{0pt} in above example by which the baseline of rows are vertically centered.

For the horizontal centering of cells contents in tabularx table, you need to define new column type, for example

\newcolumntype{C}{>{\centering\arraybackslash}X}

If the content of whole columns is in math mode, than is sensible, the whole column define to be in this mode. Then you don't need to write in each cell $<math expression>$. In this case you can define new column type as:

\newcolumntype{C}{>{\centering\arraybackslash $}X<{$}}

Complete code is then:

\documentclass{article}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash $}X<{$}}

\begin{document}
\begin{table}[h]
\begin{tabularx}{\textwidth}{ | C | C @{}m{0pt}|}
\hline
N_{1}  &  (0: 1]  & \\[3cm]  \hline
\end{tabularx}
\end{table}
\end{document}

As you see, also here is used the same trick as before. The result is slightly improved in comparison to the first example since in above MWE is by @{} eliminated inter column space.

Addendum 2: It is not clear why you use \\[3cm] to make more vertical space around cell contents. Similar effect with less problems you can achieve with change \arraystretch, for example with more reasonable added vertical space into cells you can design your table as follows:

\documentclass{article}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}% <-- cell's contend is vertically centered
\newcolumntype{C}{>{\centering\arraybackslash $}X<{$}}

\begin{document}
\begin{table}[h]
    \renewcommand{\arraystretch}{3}
    \setlength{\extrarowheight}{-2.5pt}% <-- correction of vertical centering
\begin{tabularx}{\textwidth}{ | C | C |}
\hline
N_{1}
    &  (0: 1]   \\  \hline
\end{tabularx}
\end{table}
\end{document}

As you can see, that now is not added a fake column.

enter image description here

  • Thank you, Zarko. But only with the help of this package, I was able to stretch the whole table width and make it possible to align the left, right and percentage. Maybe you can tell how to do it without this package? – Dmitry Jun 11 '16 at 9:02
  • The only thing I can do is make the table over. But align the center I can not. Since the table needs to be stretched over the entire width of the line. \begin{tabularx}\textwidth{ |X|X| } \hline $ N_{1} $ & $ ( 0: 1] $ \[5mm] \hline \end{tabularx} – Dmitry Jun 11 '16 at 9:15
  • And what does it mean - X[c,$]m{0pt} – Dmitry Jun 11 '16 at 9:20
  • @Dmitry, for details of tabu packages you need to read its documentation. X[c,$] means, that content of cells in this column is centered and in math mode. Additional column m{0pt} is the trick to achieve vertical centering of cells content in your table design. If you use tabularx the same effect you achieve with >{\centering\arraybackslash $}X<{$}, see addendum to my answer. – Zarko Jun 11 '16 at 11:15
  • Zarko, very grateful to you. You have helped me greatly. A little difficult. I understand that in your examples. Your second method is very elegant! Thanks again =) – Dmitry Jun 11 '16 at 20:30

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.