7

I'm new to latex but I'm trying to learn and am piecing together various pieces of code from different postings, so I apologize if this code is "messy".

In a table, I would like to have the widths of the columns custom-defined, and I would also like to make specific rows bold. I had found out from another posting how to make specific rows bold, but now when I add code to make my column custom-width and right-justified, the bold-faced row part doesn't work anymore. Here is an example, where you see both situations:

\documentclass{scrreprt}

%for adding the ability to make entire rows bold:
\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

%define right justified column with custom width
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}

\begin{document}
\begin{table}[ht]

\begin{tabular}{$p{2.1cm} ^p{1.6cm} R{1.5cm} R{2cm}}
\hline
header1 & header2 & header3 & header4\\
\hline
a & b & c & d\\
\rowstyle{\bfseries}
e & f & g & h\\
\hline
\end{tabular}
\end{table}
\end{document}

enter image description here

As you can see, when I use the raggedleft column type (to make it right-justified), the bold-face doesn't work.

Any ideas as to how I can get these two to work together?

1

1 Answer 1

5

You need to include the \currentrowstyle in the R column type:

\newcolumntype{R}[1]{>{\currentrowstyle\raggedleft\arraybackslash}p{#1}}

Making this change yields the complete row in bold:

enter image description here

0

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.