4

This question is about three things:

  1. Making forced line break in a cell
  2. Combining above with \rowcolors
  3. Combining above with vertical lines

1.This is obviously a common problem, since I have read several threads about this. But, I have not yet found any real solution to this extremely irritating problem, just trick-fixes.

Basically, I have a table, and in the first column I have a name, a letter and a unit, where I would like the letter and the unit on a second row to save horizontal space. I have tried:

  • p{} set column width: Doesn't work since the contents are not of the same length.
  • \newline : Which worked ONE time (?) when using tabulary, then it stopped working.
  • \parbox : But I don't want to sit and put boxwidth for each cell, that seems completely unnecessary.
  • \makecell and \thead : These two works fine and allows \\ inside! They both gives the best line break and cell shapes automatically
  • \pbox : gives similar result as above but other alignments.

BUT, now to part 2:

\makecell and \thead (and \pbox) completely messes up \rowcolors. It obviously handles the two-line cell as two cells or whatever. SO, how do I solve this problem? Is there another way of inserting line break in a cell or can the \rowcolors be manipulated? Can the \makecell be manipulated? Haven't found any answer in the CTAN manual for \makecell package

3.And further, this is also a known issue. When implementing \rowcolors, the colored rows messes up the vertical lines... They are not completely covered, but half covered of halfed in width, which looks like shit. Same crap when using \rowcolor. I've tried \setlength\arrayrulewidth{1pt} but that only increases width of all lines, not compensating those parts that are messed up. Any wonderful suggestions?

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage[table]{xcolor}
\usepackage{makecell}
\usepackage{tabulary}
\usepackage{float}

\definecolor{lg}{gray}{0.9}


\begin{document}


\begin{table}[H]
    \centering
    \rowcolors{1}{lg}{}
    \begin{tabulary}{1\textwidth}{|l|C C C C C|}\hline 
        No. & 1 & 2 & 3 & 4 & 5\\ 
        \makecell[l]{Name} & DIN CK45 & M244 & Alumec 89 & HPFS 7980 & Ti-6Al-4V (Grade 5)\\ 
        \makecell[l]{Type} & HTS & Cast Alu. & Aluminium & Fused Silica & Titanium \\
        \makecell[l]{Young's modulus \\ E [GPa]} & 210 & 90 & 71.5 & 72.7 & 113.8  \\ 
        \makecell[l]{Poisson's ratio \\ $\nu$ [1]} & 0.3 & 0.3 & 0.3 & 0.16 & 0.34 \\ 
        \makecell[l]{Yield strength \\ $\sigma_y$ [MPa]} & 500 & 185 & 550 & - & 880 \\ 
        \makecell[l]{Ultimate strength \\ $\sigma_u$ [MPa]} & 585 & 190 & 590 & 52.4 & 950 \\ 
        \makecell[l]{Reference temp. \\ $t_{ref}$ [\degree C]} & - & 25 & 25 & 25 & - \\ 
        \makecell[l]{Density \\ $\rho$ [kg/m\textsuperscript{3}]} & 7840 & 2650 & 2830 & 2201 & 4430 \\ 
        \makecell[l]{Manufacturer} & Metal Ravne & MAHLE & UDDEHOLM & CORNING & - \\ \hline 
    \end{tabulary}
    \caption{Material data}
    \label{tab:materials1}
\end{table}

\end{document}
2

Almost after one year (!) this answer will not help OP very much ... or maybe I'm wrong :). Anyway, coloring \makecell is somehow tricky. Correct coloring you obtain with put \makecell{...} into \cellcolor macro, for example:

 \cellcolor{lg}{\makecell[l]{Poisson's ratio\\ $\nu$ \cite{1}}}

However, rather this I rather redesign table into:

\documentclass{article}
\usepackage[margin=35mm]{geometry}  % <-- added
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage{siunitx}                % <-- added
\usepackage{tabularx}               % <-- changed
    \renewcommand\tabularxcolumn[1]{m{#1}}              % <-- added
    \newcolumntype{C}{>{\centering\arraybackslash}X}    % <-- added
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}  % <-- added
\definecolor{lg}{gray}{0.9}

\begin{document}

    \begin{table}
\centering
    \setlength\tabcolsep{3pt}
    \rowcolors{1}{lg}{}
\begin{tabularx}{\textwidth}{| >{\hsize=1.25\hsize}L | *{5}{>{\hsize=0.95\hsize}C} |}
    \hline
\hfil No.   & 1             & 2         & 3         & 4             & 5         \\
    \hline
Name        & DIN CK45      & M244      & Alumec 89 & HPFS 7980     & Ti-6Al-4V (Grade 5)\\
Type        & HTS           & Cast Alu. & Aluminium & Fused Silica  & Titanium  \\
Young's modulus  E [GPa]    
            & 210           & 90        & 71.5      & 72.7          & 113.8     \\
Poisson's ratio $\nu$ \cite{1}
            & 0.3           & 0.3       & 0.3       & 0.16          & 0.34      \\
Yield strength  $\sigma_y$ [MPa] 
            & 500           & 185       & 550       & --            & 880       \\
Ultimate strength $\sigma_u$ [MPa]
            & 585           & 190       & 590       & 52.4          & 950       \\
Reference temp.  $t_{\mathrm{ref}}$ [\si{\degreeCelsius}]
            & --            & 25        & 25        & 25            & --        \\
Density $\rho$ [\si{kg\per\metre\cubed}] & 7840          & 2650      & 2830      & 2201          & 4430      \\
Manufacturer& Metal Ravne   & MAHLE & UDDEHOLM  & CORNING           & --        \\ 
    \hline
\end{tabularx}
    \caption{Material data}
\label{tab:materials1}
    \end{table}
\end{document}

which gives:

enter image description here

0

I don't know how pbox messes up row colors for you but it doesn't for me:

\newcommand{\multilinebox}[1]{\pbox{\linewidth}{\vspace{.5\b‌​aselineskip}#1\vspac‌​e{.5\baselineskip}}}
  • Please make complete MWE and show its result. As answer is now, it doesn't work, – Zarko Feb 28 '17 at 17:27

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.