4

i test my solution again (with code copied from my answer) ... and it works as expected. result is as shown in answer. i haven't any idea how you succeed my mwe to not work as expected. you should have something what is hidden to me. i can only suggest you to ask new question, where you show your test mwe and obtained result and clear indication what is not as you expected. maybe someone else will see, what is the problem.

Description of problem: We have a latex tabu table with custom header's style: it has different alignment, color and shape from other table rows.

BTW XeLaTeX is used.

It is neccesarry to apply following style to header text:

  • bold;
  • aligned to horizontal center;

  • aligned to vertical center (both for one line or word wrapped cases);

  • custom color is #0070C0;

Old version of MiKTeX deleted. We have installed the latest version of MiKTeX (2.9). We fixed a bug with package fontspec (now version 2.6d).

Desired result: enter image description here

Actual result: enter image description here

We tested this code on computers of our colleagues. And result is same.

Why is alignment not working , and another person all running? What could be reason? Сan anyone else verify this code?

Is there any other way to solve original problem? It's important for us.

I copied this code from response Tabu table text-colored header: vertical and horizontal alignment, one line and word wrap cases

\documentclass[10pt, oneside, a4paper]{report}
\usepackage[left=2cm,right=1.5cm,
    top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}
\usepackage{indentfirst}
\usepackage{titlesec}
\usepackage{tabu}
\usepackage[svgnames]{xcolor}
\definecolor{DarkBlue}{HTML}{0070C0}
\definecolor{Blue}{HTML}{1C8CCC}
\usepackage{multirow}
%\usepackage{polyglossia} % i haven't this fonts
%\setmainfont[Ligatures=TeX]{Arial}% i haven't this fonts

\newcommand\ch[1]{\begin{tabular}{@{}>{\color{Blue}\bfseries}c@{}}% <-- added
                    #1
                  \end{tabular}
                  }

\begin{document}
\taburulecolor{DarkBlue}
\tabulinesep=1mm       
\begin{tabu} to 170 mm {
    |X[2]       %  |X[2,m]
    |X[1.5]     %  |X[1.5,m]
    |X[0.6, C]  %  |X[0.6, C,m]
    |X[2]       %  |X[2,m]
    |X[0.6, C]| %  |X[0.6, C,m]|
    }
\hline
\ch{Status}
    & \ch{Visual indication:\\ color and\\ indication type}
    & \ch{Symbol}
    & \ch{Audible signal}
    & \ch{Priority}\\ \hline   

Alarm active, not acknowledge
    & Red, blinking
    & picture
    & Accompanied by an audible signal, as 3 short audible signals repeated every 7 s
    & High
    \\ \hline    
Alarm active, silenced
    & Red, blinking
    & picture
    & Silent
    &
    \\ \hline
\end{tabu}
\end{document}
  • Welcome to TeX.SX! You are right. The image is of an other version of the answer (see version 1). @Zarko could you fix it please? (and answer with version one) here. – Bobyandbob Sep 5 '17 at 15:21
  • @Bobyandbob, i fixed my spurious code now. see my answer below and correction in the mine original answer. – Zarko Sep 6 '17 at 9:48
3

I suggest you put each heading inside a \multicolumn{1}{c}{...} via the following macros:

\newcommand{\chbody}[1]{\begin{tabular}{@{}>{\color{Blue}\bfseries}c@{}}#1\end{tabular}}
\newcommand{\ch}[1]{\multicolumn{1}{c|}{\chbody{#1}}}
\newcommand{\fch}[1]{\multicolumn{1}{|c|}{\chbody{#1}}}

(the \fch is just for the first column that also needs a vertical rule on the left).

This gives centered headings

Sample output

\documentclass[10pt, oneside, a4paper]{report}

\usepackage[left=2cm,right=1.5cm,
    top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}
\usepackage{tabu}
\usepackage[svgnames]{xcolor}
\definecolor{DarkBlue}{HTML}{0070C0}
\definecolor{Blue}{HTML}{1C8CCC}

\newcommand{\chbody}[1]{\begin{tabular}{@{}>{\color{Blue}\bfseries}c@{}}#1\end{tabular}}
\newcommand{\ch}[1]{\multicolumn{1}{c|}{\chbody{#1}}}
\newcommand{\fch}[1]{\multicolumn{1}{|c|}{\chbody{#1}}}

\begin{document}

\taburulecolor{DarkBlue}%
\tabulinesep=1mm
\begin{tabu} to 170 mm {
    |X[2]       %  |X[2,m]
    |X[1.5]     %  |X[1.5,m]
    |X[0.6, C]  %  |X[0.6, C,m]
    |X[2]       %  |X[2,m]
    |X[0.6, C]| %  |X[0.6, C,m]|
    }
\hline
\fch{Status}
    & \ch{Visual indication:\\ color and\\ indication type}
    & \ch{Symbol}
    & \ch{Audible signal}
    & \ch{Priority}\\ \hline
\tabuphantomline
Alarm active, not acknowledge
    & Red, blinking
    & picture
    & Accompanied by an audible signal, as 3 short audible signals repeated every 7 s
    & High
    \\ \hline
Alarm active, silenced
    & Red, blinking
    & picture
    & Silent
    &
    \\ \hline
\end{tabu}
\end{document}

Note I have added \tabuphantomline as recommended by the package's documentation and I have removed other unused packages from the preamble.

|improve this answer|||||
1

also works with adding the missed part (what embarrassing) of my definition of \ch command:

    \newcommand\ch[1]{\centering% <-- missed, sorry
            \begin{tabular}{@{}>{\color{Blue}\bfseries}c@{}}
                        #1
                      \end{tabular}
                      }

sorry, i overlooked this twice ... (in result and at copy of the wrong version of my "development" of the answer) :-). this correction i also add to original answer

now complete mwe is (also tested with xelatex):

\documentclass[10pt, oneside, a4paper]{report}
\usepackage[left=2cm,right=1.5cm,
    top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}
\usepackage{indentfirst}
\usepackage{titlesec}
\usepackage{tabu}
\usepackage[svgnames]{xcolor}
\definecolor{DarkBlue}{HTML}{0070C0}
\definecolor{Blue}{HTML}{1C8CCC}
\usepackage{multirow}
%\usepackage{polyglossia} % i haven't this fonts
%\setmainfont[Ligatures=TeX]{Arial}% i haven't this fonts

\newcommand\ch[1]{\centering% <-- added
        \begin{tabular}{@{}>{\color{Blue}\bfseries}c@{}}
                    #1
                  \end{tabular}
                  }

\begin{document}
\taburulecolor{DarkBlue}
\tabulinesep=1mm
\begin{tabu} to 170 mm {
    |X[2]       %  |X[2,m]
    |X[1.5]     %  |X[1.5,m]
    |X[0.6, C]  %  |X[0.6, C,m]
    |X[2]       %  |X[2,m]
    |X[0.6, C]| %  |X[0.6, C,m]|
    }
\hline
\ch{Status (now centered)}
    & \ch{Visual indication:\\ color and\\ indication type}
    & \ch{Symbol}
    & \ch{Audible signal}
    & \ch{Priority}\\ \hline

Alarm active, not acknowledge
    & Red, blinking
    & picture
    & Accompanied by an audible signal, as 3 short audible signals repeated every 7 s
    & High
    \\ \hline
Alarm active, silenced
    & Red, blinking
    & picture
    & Silent
    &
    \\ \hline
\end{tabu}
\end{document}

enter image description here

note: using of different font (enabled by xelatex) may require to increase columns widths the narrower columns: |X[0.6, C].

|improve this answer|||||

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.