Graphics, Figures & TablesHow to highlight the row in a thinner way? and column

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
gcheer3
Posts: 41
Joined: Wed Jun 25, 2008 4:39 pm

How to highlight the row in a thinner way? and column

Post by gcheer3 »

Hello,

Anyone please give me some suggestions on this problem.
I have a table as follows:

Code: Select all

\begin{tabular}{ccccr}
	\hline
$k$ &  $x_1^k$    &   $x_2^k$  & $x_3^k$   & remarks  \\
	\hline
0   & -0.3 & 0.6 & 0.7  &  \\[0.2ex]
\rowcolor[gray]{.8}
1   & 0.47102965 & 0.04883157 & -0.53345964  & *\\[2.5ex]

2   & 0.49988691 & 0.00228830 & -0.52246185 & $s_3$ \\[0.2ex]
\rowcolor[gray]{.8}
3   & 0.49999976 & 0.00005380 & -0.52365600  & \\[2.5ex]
4   & 0.5 & 0.00000307 & -0.52359743  & $\epsilon < 10^{-5}$ \\[0.2ex]
5   & 0.5 & 0 & -0.52359878  & $\epsilon < \xi $ \\[0.2ex]
	\hline
\end{tabular}
I purposely make a bigger space between every two rows(every two number is sort of in one group). So "\\[2.5ex]" did the work. But now I want to highlight two rows with 'k=1' and 'k=3'. I used \rowcolor[gray]{.8}, unfortunately, since there is a gap between 'k=1' and 'k=2', the grey highlight area is too wide. In other words, is there is a way that I can still highlight the row 'k=1', but only tightly highlight the row, not so much area under?

Also, how can I just simply highlight the fourth column in the table including the column title 'x_3^k'. Somehow, I cannot make it work.

Many thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How to highlight the row in a thinner way? and column

Post by gmedina »

Hi,

for the first issue, you can add two fictitious rows; for the second problem, use \columncolor and the >{...} construct (see the array package documentation); depending on the actual coloring pattern required you might also need to use \cellcolor (my code includes two possibilities):

Code: Select all

\documentclass{article} 
\usepackage{array}
\usepackage[table]{xcolor}

\begin{document}

\begin{tabular}{ccc>{\columncolor{blue!50}}cr}
  \hline
  $k$ &  $x_1^k$    &   $x_2^k$  & $x_3^k$   & remarks  \\
  \hline
  0 & -0.3 & 0.6 & 0.7  &  \\[0.2ex]
  \rowcolor[gray]{.8}
  1 & 0.47102965 & 0.04883157 & -0.53345964  & *\\ \\[-0.1ex]
  2 & 0.49988691 & 0.00228830 & -0.52246185 & $s_3$ \\[0.2ex]
  \rowcolor[gray]{.8}
  3 & 0.49999976 & 0.00005380 & -0.52365600  & \\ \\[-0.1ex]
  4 & 0.5 & 0.00000307 & -0.52359743  & $\epsilon < 10^{-5}$ \\[0.2ex]
  5 & 0.5 & 0 & -0.52359878  & $\epsilon < \xi $ \\[0.2ex]
   \hline
\end{tabular}

\vspace{1cm}

\begin{tabular}{ccc>{\columncolor{blue!50}}cr}
  \hline
  $k$ &  $x_1^k$    &   $x_2^k$  & $x_3^k$   & remarks  \\
  \hline
  0 & -0.3 & 0.6 & 0.7  &  \\[0.2ex]
  \rowcolor[gray]{.8}
  1 & 0.47102965 & 0.04883157 & \cellcolor{blue!50}-0.53345964  & *\\ \\[-0.1ex]
  2 & 0.49988691 & 0.00228830 & -0.52246185 & $s_3$ \\[0.2ex]
  \rowcolor[gray]{.8}
  3 & 0.49999976 & 0.00005380 & \cellcolor{blue!50}-0.52365600  & \\ \\[-0.1ex]
  4 & 0.5 & 0.00000307 & -0.52359743  & $\epsilon < 10^{-5}$ \\[0.2ex]
  5 & 0.5 & 0 & -0.52359878  & $\epsilon < \xi $ \\[0.2ex]
   \hline
\end{tabular}

\end{document} 
1,1,2,3,5,8,13,21,34,55,89,144,233,...
gcheer3
Posts: 41
Joined: Wed Jun 25, 2008 4:39 pm

Re: How to highlight the row in a thinner way? and column

Post by gcheer3 »

Hello gmedina,

Thanks a lot for your help. You solved both my problems!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to highlight the row in a thinner way? and column

Post by localghost »

Now that the problem is obviously solved, please be so kind and mark the topic accordingly as exactly described in Section 3 of the Board Rules.


Best regards
Thorsten
Post Reply