Beamer: 테이블의 두 번째 열마다 색상을 지정합니다.

Beamer: 테이블의 두 번째 열마다 색상을 지정합니다.

내 비머 프레임 중 하나에 테이블을 포함하려고 합니다. 이 테이블의 두 번째 열마다 배경이 회색이 되도록 하고 싶습니다. 내 LaTeX 문서에서 다음 코드가 작동했습니다.

\definecolor{Gray}{gray}{0.9}
\newcolumntype{g}{>{\columncolor{Gray}}c}
\begin{table}[ht]
            \centering
            \begin{tabular}{c|g|c|g|c|g}
                5.35 & 0.35 & 5.61 & -0.39 & 6.84 & -0.16 \\
                5.45 & 0.45 & 5.52 & -0.48 & 6.84 & -0.16 \\
                5.45 & 0.45 & 5.51 & -0.49 & 6.96 & -0.04 \\
                5.45 & 0.45 & 5.63 & -0.37 & 6.96 & -0.04 
            \end{tabular}
            \caption{my caption.}
            \label{myTable}
        \end{table}

그러나 이는 빔머에서는 작동하지 않습니다. 패키지를 사용하고 있습니다 \usepackage{xcolor}. 이제 내가 찾은 것은이 블로그\documentclass[xcolor=table]{beamer}내 문서 클래스를 사용하도록 변경해야 \usepackage[table]{xcolor}모든 것이 작동합니다. 여기서 문제는 비머 템플릿이 아닌 맞춤형 템플릿을 사용하고 있다는 것입니다. 어쨌든, 나는 이 문제에 대해 머리를 감을 수 없습니다. 그렇게 복잡해서는 안 됩니다, 그렇죠?

불행하게도 팝업되는 오류 메시지는 전혀 도움이 되지 않습니다. 그것은 간단하게 말합니다:Undefined control sequence \end{frame}

답변1

패키지는 패키지 beamer를 로드합니다 xcolor. 에 대한 일부 옵션을 추가하려면 xcolor문서 클래스 옵션 사이에 이 옵션을 작성해야 합니다.

\documentclass[table]{beamer} % <--- option "table"  is passed to "xcolor" pacage
\definecolor{Gray}{gray}{0.9}
\newcolumntype{g}{>{\columncolor{Gray}}c}

\begin{document}
\begin{frame}
\frametitle{My colored table}
\begin{table}% table in beamer isn't float ...
    \centering
    \begin{tabular}{c|g|c|g|c|g}
        5.35 & 0.35 & 5.61 & -0.39 & 6.84 & -0.16 \\
        5.45 & 0.45 & 5.52 & -0.48 & 6.84 & -0.16 \\
        5.45 & 0.45 & 5.51 & -0.49 & 6.96 & -0.04 \\
        5.45 & 0.45 & 5.63 & -0.37 & 6.96 & -0.04
    \end{tabular}
    \caption{my caption.}
    \label{myTable}
\end{table}
\end{frame}
\end{document}

원하는 결과를 제공합니다.

여기에 이미지 설명을 입력하세요

답변2

tikzpicture수업 에 잘 적응하기 때문에 beamer(Till Tantao와 같은 저자가 작성함) 테이블을 tikzpicture. 옵션을 로드할 필요가 없습니다 [table].

여기에 이미지 설명을 입력하세요

\documentclass{beamer}
\usepackage{tikz}
% I mimick the way of putting a row in a table
\newcommand{\putrow}[7]{
\path (0,#1) node{#2}
++(0:1) node{#3} ++(0:1) node{#4}
++(0:1) node{#5} ++(0:1) node{#6} ++(0:1) node{#7};
}

\begin{document}
\begin{frame}
\frametitle{Colored table}
\centering
\begin{tikzpicture}[xscale=1.2,yscale=.5]
\begin{scope}[shift={(-.5,.5)}]
\foreach \i in {1,3,5} \fill[blue!20] (\i,0) rectangle +(1,-4);
\foreach \i in {1,...,6} \draw[blue] (\i,0)--+(-90:4);
\end{scope}
\putrow{0}{5.35}{0.35}{5.61}{-0.39}{6.84}{-0.16}
\putrow{-1}{5.45}{0.45}{5.52}{-0.48}{6.84}{-0.16}
\putrow{-2}{5.45}{0.45}{5.51}{-0.49}{6.96}{-0.04}
\putrow{-3}{5.45}{0.45}{5.63}{-0.37}{6.96}{-0.04}

\path (current bounding box.south) node[below=2mm,blue]
{My colored table as a tikzpicture};
\end{tikzpicture}
\end{frame}
\end{document}

관련 정보