23

This appears to be a problem which a few people have had before, but since I've been unable to find a solution which works I thought I should ask again.

I have a LaTeX table of 5 columns width and about 100 rows depth, and I'd like to format whole rows in bold font as opposed to changing each individual cell entry to bold. I don't want every single row to be bold, only a certain selection.

I've tried this solution:

Make first row of table all bold

This doesn't throw up errors, but only changes the first entry of the row to bold font, rather than all the entries in the row. My code is below.

\begin{table}[htbp]
\caption{List of the gamma rays from TS1 and TS2 in the energy region from 140 keV to 655 keV}
\begin{adjustbox}{center}
\begin{tabular}{cccrcc}
\toprule
Energy & Energy & Origin & \multicolumn{1}{c}{Branching} & Av. peak  & Av. Peak \\

Measured & Measured & \&    & \multicolumn{1}{c}{Ratio } & count rate in & count rate \\
TS1   & TS2   & Process & \multicolumn{1}{c}{(emission} & TS1 [1/hr]  & TS2  \\
 (keV) & (keV) &       & \multicolumn{1}{c}{probability} & Beam on  & [1/hr]  \\
      &       &       & \multicolumn{1}{c}{per decay)} & (Beam off) &  \\
      \midrule
140.38 & 140.31 & 75m-Ge (IT) & 39\%  & 461 (0) & 17 \\
159.70 & --    & 63-Cu (n,G) & 15.00\% & 411 (0) & -- \\
175.77 & --    & 70-Ge (n,G) & 25.00\% & 272 (0) & -- \\
186.39 & 186.59 & 235-U (A) & 57.20\% & 44 (56) & 43 \\
199.02 & 199.07 & 71-Ge (EC) & N/A   & 440 (0) & 38 \\
239.20 & 239.19 & 212-Pb (B-) & 43.30\% & 192 (197) & 186 \\
242.41 & 242.59 & 214-Pb (B-) & 7.43\% & 52 (57) & 79 \\
250.75 & --    & 39-Cl (B-) & 46.30\% & 177 (0) & -- \\
--    & 272.36 & 173-Lu (EC) & 21.20\% & --    & 48 \\
278.51 & --    & 63-Cu (n,G) & 24.00\% & 296 (0) & -- \\
295.65 & 295.55 & 214-Pb (B-) & 19.30\% & 92 (133) & 134 \\
320.41 & --    & 51-Cr (EC) & 10.00\% & 16 (17) & -- \\
338.61 & 338.78 & 228-Ac (B-) & 11.27\% & 43 (41) & 50 \\
352.28 & 352.22 & 214-Pb (B-) & 19.30\% & 449 (232) & 307 \\
352.28 & 352.22 & 56-Fe (n,G) & 9.50\% & 449 (232) & 307 \\
440.09 & --    & 23-Mg (EC) & 8.20\% & 131 (0) & -- \\
463.21 & 463.31 & 228-Ac (B-) & 4.40\% & 25 (17) & 14 \\
472.27 & --    & 23-Na (n,G) & 90.39\% & 81 (0) & -- \\
477.77 & --    & 7-Be (EC) & 10.52\% & 1457 (1501) & -- \\
500.01 & --    & 70-Gen (n,G) & 24.10\% & 93 (0) & -- \\
510.99 & 511.02 & Ann.  & N/A   & 116190 (262) & 18607 \\
--    & 558.42 & 113-Cd (n,G) & 74.40\% & --    & 141 \\
583.45 & 583.31 & 208-Tl (B-) & 84.50\% & 82 (91) & 84 \\
595.96 & 596.31 & 74-Ge (n,n' G) & 100.00\% & 272(0) & 15 \\
609.26 & --    & 74-Ge (n,n' G) & 18.20\% & 275 (219) & -- \\
609.48 & 609.55 & 214-Bi (B-) & 46.10\% & 275 (219) & 287 \\
--    & 651.28 & 113-Cd (n,G) & 14.09\% & --    & 35 \\
\bottomrule
\end{tabular}%
\end{adjustbox}
\label{tab:addlabel}%
\end{table}%

Thanks for any guidance.

Matt
  • 231

3 Answers3

26

Maybe this? I introduce a \setrow{...} macro invoked on the first element of a row, which applies to each cell of that row (and is then reset). It employs the >{} and <{} feature of tabularx.

\documentclass{article}
\usepackage{tabularx}
\newcommand\setrow[1]{\gdef\rowmac{#1}#1\ignorespaces}
\newcommand\clearrow{\global\let\rowmac\relax}
\clearrow
\begin{document}
\begin{tabular}{>{\rowmac}c|>{\rowmac}c|>{\rowmac}c<{\clearrow}}
a & b & c\\
\setrow{\bfseries}d & e & f\\
e & f& g\\
h & i & j\\
\setrow{\itshape} k & l & m\\
n & o & p
\end{tabular}
\end{document}

enter image description here

As applied to the OP's problem:

\documentclass{article}
\usepackage{tabularx,adjustbox,booktabs}
\newcommand\setrow[1]{\gdef\rowmac{#1}#1\ignorespaces}
\newcommand\clearrow{\global\let\rowmac\relax}
\clearrow
\begin{document}
\begin{adjustbox}{center}
\begin{tabular}{>{\rowmac}c>{\rowmac}c>{\rowmac}c>{\rowmac}r>{\rowmac}c>{\rowmac}%
  c<{\clearrow}}
\toprule
Energy & Energy & Origin & \multicolumn{1}{c}{Branching} & Av. peak  & Av. Peak \\

Measured & Measured & \&    & \multicolumn{1}{c}{Ratio } & count rate in & count rate \\
TS1   & TS2   & Process & \multicolumn{1}{c}{(emission} & TS1 [1/hr]  & TS2  \\
 (keV) & (keV) &       & \multicolumn{1}{c}{probability} & Beam on  & [1/hr]  \\
      &       &       & \multicolumn{1}{c}{per decay)} & (Beam off) &  \\
      \midrule
140.38 & 140.31 & 75m-Ge (IT) & 39\%  & 461 (0) & 17 \\
159.70 & --    & 63-Cu (n,G) & 15.00\% & 411 (0) & -- \\
175.77 & --    & 70-Ge (n,G) & 25.00\% & 272 (0) & -- \\
\setrow{\bfseries}186.39 & 186.59 & 235-U (A) & 57.20\% & 44 (56) & 43 \\
199.02 & 199.07 & 71-Ge (EC) & N/A   & 440 (0) & 38 \\
239.20 & 239.19 & 212-Pb (B-) & 43.30\% & 192 (197) & 186 \\
242.41 & 242.59 & 214-Pb (B-) & 7.43\% & 52 (57) & 79 \\
250.75 & --    & 39-Cl (B-) & 46.30\% & 177 (0) & -- \\
--    & 272.36 & 173-Lu (EC) & 21.20\% & --    & 48 \\
\setrow{\bfseries}278.51 & --    & 63-Cu (n,G) & 24.00\% & 296 (0) & -- \\
\setrow{\bfseries}295.65 & 295.55 & 214-Pb (B-) & 19.30\% & 92 (133) & 134 \\
320.41 & --    & 51-Cr (EC) & 10.00\% & 16 (17) & -- \\
338.61 & 338.78 & 228-Ac (B-) & 11.27\% & 43 (41) & 50 \\
352.28 & 352.22 & 214-Pb (B-) & 19.30\% & 449 (232) & 307 \\
352.28 & 352.22 & 56-Fe (n,G) & 9.50\% & 449 (232) & 307 \\
440.09 & --    & 23-Mg (EC) & 8.20\% & 131 (0) & -- \\
463.21 & 463.31 & 228-Ac (B-) & 4.40\% & 25 (17) & 14 \\
\setrow{\bfseries}472.27 & --    & 23-Na (n,G) & 90.39\% & 81 (0) & -- \\
477.77 & --    & 7-Be (EC) & 10.52\% & 1457 (1501) & -- \\
500.01 & --    & 70-Gen (n,G) & 24.10\% & 93 (0) & -- \\
510.99 & 511.02 & Ann.  & N/A   & 116190 (262) & 18607 \\
--    & 558.42 & 113-Cd (n,G) & 74.40\% & --    & 141 \\
\setrow{\bfseries}583.45 & 583.31 & 208-Tl (B-) & 84.50\% & 82 (91) & 84 \\
595.96 & 596.31 & 74-Ge (n,n' G) & 100.00\% & 272(0) & 15 \\
\setrow{\bfseries}609.26 & --    & 74-Ge (n,n' G) & 18.20\% & 275 (219) & -- \\
609.48 & 609.55 & 214-Bi (B-) & 46.10\% & 275 (219) & 287 \\
--    & 651.28 & 113-Cd (n,G) & 14.09\% & --    & 35 \\
\bottomrule
\end{tabular}%
\end{adjustbox}
\end{document}

enter image description here

4

The first answer to the question you linked in your question (https://tex.stackexchange.com/a/4816/36296) seems to work just fine. If only the first entry was coloured, did you remember to adjust the alignment options to $c^c^c^r^c^c?

\documentclass{article}

\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage{booktabs}

\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
    #1\ignorespaces
}

\begin{document}

\begin{table}[htbp]
    \caption{List of the gamma rays from TS1 and TS2 in the energy region from 140 keV to 655 keV}
    \begin{adjustbox}{center}
        \begin{tabular}{$c^c^c^r^c^c}
            \toprule
            \rowstyle{\bfseries}
            Energy & Energy & Origin & \multicolumn{1}{^c}{Branching} & Av. peak  & Av. Peak \\

            \rowstyle{\bfseries}Measured & Measured & \&    & \multicolumn{1}{^c}{Ratio } & count rate in & count rate \\
            \rowstyle{\bfseries}TS1   & TS2   & Process & \multicolumn{1}{^c}{(emission} & TS1 [1/hr]  & TS2  \\
            \rowstyle{\bfseries}(keV) & (keV) &       & \multicolumn{1}{^c}{probability} & Beam on  & [1/hr]  \\
            \rowstyle{\bfseries}&       &       & \multicolumn{1}{^c}{per decay)} & (Beam off) &  \\
            \midrule
            140.38 & 140.31 & 75m-Ge (IT) & 39\%  & 461 (0) & 17 \\
            159.70 & --    & 63-Cu (n,G) & 15.00\% & 411 (0) & -- \\
            175.77 & --    & 70-Ge (n,G) & 25.00\% & 272 (0) & -- \\
            186.39 & 186.59 & 235-U (A) & 57.20\% & 44 (56) & 43 \\
            199.02 & 199.07 & 71-Ge (EC) & N/A   & 440 (0) & 38 \\
            239.20 & 239.19 & 212-Pb (B-) & 43.30\% & 192 (197) & 186 \\
            242.41 & 242.59 & 214-Pb (B-) & 7.43\% & 52 (57) & 79 \\
            \rowstyle{\bfseries}250.75 & --    & 39-Cl (B-) & 46.30\% & 177 (0) & -- \\
            --    & 272.36 & 173-Lu (EC) & 21.20\% & --    & 48 \\
            278.51 & --    & 63-Cu (n,G) & 24.00\% & 296 (0) & -- \\
            295.65 & 295.55 & 214-Pb (B-) & 19.30\% & 92 (133) & 134 \\
            320.41 & --    & 51-Cr (EC) & 10.00\% & 16 (17) & -- \\
            338.61 & 338.78 & 228-Ac (B-) & 11.27\% & 43 (41) & 50 \\
            352.28 & 352.22 & 214-Pb (B-) & 19.30\% & 449 (232) & 307 \\
            352.28 & 352.22 & 56-Fe (n,G) & 9.50\% & 449 (232) & 307 \\
            440.09 & --    & 23-Mg (EC) & 8.20\% & 131 (0) & -- \\
            463.21 & 463.31 & 228-Ac (B-) & 4.40\% & 25 (17) & 14 \\
            472.27 & --    & 23-Na (n,G) & 90.39\% & 81 (0) & -- \\
            477.77 & --    & 7-Be (EC) & 10.52\% & 1457 (1501) & -- \\
            500.01 & --    & 70-Gen (n,G) & 24.10\% & 93 (0) & -- \\
            510.99 & 511.02 & Ann.  & N/A   & 116190 (262) & 18607 \\
            --    & 558.42 & 113-Cd (n,G) & 74.40\% & --    & 141 \\
            583.45 & 583.31 & 208-Tl (B-) & 84.50\% & 82 (91) & 84 \\
            595.96 & 596.31 & 74-Ge (n,n' G) & 100.00\% & 272(0) & 15 \\
            609.26 & --    & 74-Ge (n,n' G) & 18.20\% & 275 (219) & -- \\
            609.48 & 609.55 & 214-Bi (B-) & 46.10\% & 275 (219) & 287 \\
            --    & 651.28 & 113-Cd (n,G) & 14.09\% & --    & 35 \\
            \bottomrule
        \end{tabular}%
    \end{adjustbox}
    \label{tab:addlabel}%
\end{table}%


\end{document}

enter image description here

2

The environment {NiceTabular} of nicematrix has a built-in command \RowStyle to specify formatting instructions to the (end of the) current row.

\documentclass{article}
\usepackage{booktabs}
\usepackage{nicematrix}
\usepackage{adjustbox}

\begin{document} \begin{adjustbox}{center} \begin{NiceTabular}{cccrcc} \toprule Energy & Energy & Origin & \multicolumn{1}{c}{Branching} & Av. peak & Av. Peak \

Measured & Measured & &amp; & \multicolumn{1}{c}{Ratio } & count rate in & count rate \ TS1 & TS2 & Process & \multicolumn{1}{c}{(emission} & TS1 [1/hr] & TS2 \ (keV) & (keV) & & \multicolumn{1}{c}{probability} & Beam on & [1/hr] \ & & & \multicolumn{1}{c}{per decay)} & (Beam off) & \ \midrule 140.38 & 140.31 & 75m-Ge (IT) & 39% & 461 (0) & 17 \ 159.70 & -- & 63-Cu (n,G) & 15.00% & 411 (0) & -- \ 175.77 & -- & 70-Ge (n,G) & 25.00% & 272 (0) & -- \ \RowStyle{\bfseries}186.39 & 186.59 & 235-U (A) & 57.20% & 44 (56) & 43 \ 199.02 & 199.07 & 71-Ge (EC) & N/A & 440 (0) & 38 \ 239.20 & 239.19 & 212-Pb (B-) & 43.30% & 192 (197) & 186 \ 242.41 & 242.59 & 214-Pb (B-) & 7.43% & 52 (57) & 79 \ 250.75 & -- & 39-Cl (B-) & 46.30% & 177 (0) & -- \ -- & 272.36 & 173-Lu (EC) & 21.20% & -- & 48 \ \RowStyle{\bfseries}278.51 & -- & 63-Cu (n,G) & 24.00% & 296 (0) & -- \ \RowStyle{\bfseries}295.65 & 295.55 & 214-Pb (B-) & 19.30% & 92 (133) & 134 \ 320.41 & -- & 51-Cr (EC) & 10.00% & 16 (17) & -- \ 338.61 & 338.78 & 228-Ac (B-) & 11.27% & 43 (41) & 50 \ 352.28 & 352.22 & 214-Pb (B-) & 19.30% & 449 (232) & 307 \ 352.28 & 352.22 & 56-Fe (n,G) & 9.50% & 449 (232) & 307 \ 440.09 & -- & 23-Mg (EC) & 8.20% & 131 (0) & -- \ 463.21 & 463.31 & 228-Ac (B-) & 4.40% & 25 (17) & 14 \ \RowStyle{\bfseries}472.27 & -- & 23-Na (n,G) & 90.39% & 81 (0) & -- \ 477.77 & -- & 7-Be (EC) & 10.52% & 1457 (1501) & -- \ 500.01 & -- & 70-Gen (n,G) & 24.10% & 93 (0) & -- \ 510.99 & 511.02 & Ann. & N/A & 116190 (262) & 18607 \ -- & 558.42 & 113-Cd (n,G) & 74.40% & -- & 141 \ \RowStyle{\bfseries}583.45 & 583.31 & 208-Tl (B-) & 84.50% & 82 (91) & 84 \ 595.96 & 596.31 & 74-Ge (n,n' G) & 100.00% & 272(0) & 15 \ \RowStyle{\bfseries}609.26 & -- & 74-Ge (n,n' G) & 18.20% & 275 (219) & -- \ 609.48 & 609.55 & 214-Bi (B-) & 46.10% & 275 (219) & 287 \ -- & 651.28 & 113-Cd (n,G) & 14.09% & -- & 35 \ \bottomrule \end{NiceTabular}% \end{adjustbox} \end{document}

Output of the above code

F. Pantigny
  • 40,250