Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

\centering command, that I use in my document gives strange output - values aren't centered equally

image below should let you understand (elements in red frame and two not framed "value" strings in table, are not centered) enter image description here code for this page/document:

\documentclass[twoside,titlepage]{article}
\usepackage[polish]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,inner=3.5cm,outer=2.0cm,top=2.0cm,bottom=2.0cm]{geometry}
\usepackage{multicol}
\usepackage[titletoc,title]{appendix}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{mathtools}
\newcommand{\appendixtitle}[2]{\begin{center}(#1)\\ ~ \\ {\Large #2}\end{center}}
\newcolumntype{z}[1]{%
    >{\centering\hspace{0pt}}m{#1}}%
\newcommand{\tnl}{\tabularnewline}
\usepackage{lipsum}
\begin{document}
    \begin{appendices}
        \section[~]{\centering}
        \appendixtitle{type}{appendix title}
        \newlength{\celllen}
        \setlength{\celllen}{\textwidth/5}
        \lipsum[1]
        \begin{table}[!htb]
            \caption{multirowed}
            \centering
            \begin{tabular}{|*{4}{z{\celllen}|}}
                \hline
                \multirow{2}{\celllen}{\centering
                    very very very long cell \newline symbol \newline unit
                } & \multicolumn{3}{c|}{ \textbf{   Description } } \tnl
                & value & value & value \tnl \hline
            \end{tabular}
        \end{table}

        \begin{table}[!htb]
            \caption{final}
            \centering
            \begin{tabular}{|*{4}{z{\celllen}|}}
                \hline
                \multirow{5}{\celllen}{\centering
                    very very very long cell \newline symbol \newline unit
                } & \multicolumn{3}{c|}{ \textbf{   Description } } \tnl
                & value & value & value \tnl \cline{2-4}
                & \multicolumn{3}{c|}{ \textbf{ Description }, symbol, unit } \tnl
                & value & value & value \tnl \cline{2-4}
                & \multicolumn{3}{c|}{ \textbf{ Description }, symbol, unit } \tnl \hline
                value \newline (comment) & value & value & value \tnl \hline
                value \newline (comment) & value & value & value \tnl \hline
            \end{tabular}
        \end{table}
    \end{appendices}
\end{document}

How can I make all those red-framed-texts (and "value" strings I forgot to frame) centered, just like other strings

P.S. help with first table (text overflow) is greatly appreciated ;)

share|improve this question

2 Answers 2

up vote 8 down vote accepted

Don't use \newline but \\.

\documentclass{article}
\begin{document}
\centering

aaa\\ bbbbbb\\ cccccc

aaa\newline bbbbbb\newline cccccc

\end{document}

And try to make simpler examples. Wading through all this \multirow etc doesn't make it easy to debug your code.

share|improve this answer
    
It's my first real LaTeX document, and first real problem, where I couldn't find answer, so please forgive me my long example here ;) –  Soul Reaver Feb 12 '12 at 18:15

the mechanism for \newline makes this command be equivalent to \\, so what precedes it is treated as an ordinary "paragraph" (ending with \parfillskip glue, messing up the centering). (you are using this inside a table, which means you shouldn't use \\ directly.)

change \newline to \break, avoiding all fancy additions (but also all checking), and every line will center as desired.

share|improve this answer
    
Using \` to end centered lines will works fine in the example. \` to end tabular lines will not work in the cell with centering, so you should \tabularnewline instead (or give \` the "end tabular line" meaning back with \\arraybackslash`) –  Ulrike Fischer Feb 12 '12 at 18:01
    
@ulrike, sorry, your comment isn't comprehensible because the attempt to "code-ify" the double backslash isn't working correctly. i guess i should bring that problem up on meta. i've been burned by it several times, so now i put spaces around the two backslashes within the upticks. –  barbara beeton Feb 12 '12 at 18:05
    
@ulrike -- the double backslash mess in comments has been discussed here on meta. seems it's not likely to change. bummer. –  barbara beeton Feb 12 '12 at 18:10
    
@barbara beeton, thanks, your solution worked too –  Soul Reaver Feb 12 '12 at 18:17
    
@barbara: Sorry I forget (again) about the problem with the backslashes. So here the hopefully corrected comment: Using ` \\ ` to end centered lines will works fine in the example. ` \\ ` to end tabular lines will not work in the cell with centering, so you should \tabularnewline instead (or give ` \\ ` the "end tabular line" meaning back with ` \arraybackslash `) –  Ulrike Fischer Feb 12 '12 at 18:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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