부분 표 형식* 행을 색상으로 채우기

부분 표 형식* 행을 색상으로 채우기

다른 선 두께를 얻기 위해 등 을 tabular*사용하고 싶기 때문에 테이블을 생성 하려고 합니다 . 그러나 아래 시도에서 테이블의 섹션에도 색상을 지정하려고 하면 다음과 같은 색상의 공백이 나타납니다.midrulebottomrule

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

나는 이것들을 보았다관련 솔루션하지만 아직 원하는 결과를 얻지 못했기 때문에 여기서 사용할 수 있는 더 간단한 솔루션이 있는지 알고 싶었습니다.

이것은 내 코드입니다.

\documentclass{article}
\usepackage{float}
\usepackage{xcolor,colortbl,tabularx}
\usepackage{bigstrut}
\definecolor{LightGray}{gray}{0.9}

\begin{document}

\begin{table}[H]
\centering
  \caption{Not too good looking table here.\label{tab:table1}}
  \footnotesize
% Table generated by Excel2LaTeX from sheet 'Sheet2'
    \begin{tabularx}{\textwidth}{c @{\extracolsep{\fill}} c|ccc}
    %\begin{tabular*}{cc|cc}
    %\toprule
    \hline
    \multicolumn{2}{c|}{\textbf{Test1}} & \multicolumn{2}{c}{\textbf{Test2}} \bigstrut[t]\\
   Test11 & Test12 & Test13 & Test14 \bigstrut[b]\\
   %\midrule
    \hline
    FLTR2 & 2     & 40    & FLTR0 \bigstrut[t]\\
    FLTR0 & 80    & 80    & FLTR0 \\
    \rowcolor[rgb]{ 1,  .78,  .808} \textcolor[rgb]{ .612,  0,  .024}{FLTR0} & \textcolor[rgb]{ .612,  0,  .024}{160} & \textcolor[rgb]{ .612,  0,  .024}{204} & \textcolor[rgb]{ .612,  0,  .024}{FLTR4} \\
    FLTR6 & 6     & 44    & FLTR4 \\
    \rowcolor[rgb]{ 1,  .78,  .808} \textcolor[rgb]{ .612,  0,  .024}{FLTR16} & \textcolor[rgb]{ .612,  0,  .024}{16} & \cellcolor[rgb]{ 1,  1,  1}43 & \cellcolor[rgb]{ 1,  1,  1}FLTR3 \\
    FLTR4 & 44    & 6     & FLTR6 \bigstrut[b]\\
    \hline
    %\bottomrule
    \end{tabularx}%
    %\end{tabular*}
\end{table}

\end{document}

간격 없이 셀을 채우는 동시에 색상을 사용하는 방법 등을 사용 toprule합니까 midrule?

답변1

  • @{\extracolsep{\fill}}색상을 지정할 수 없는 열 사이에 추가 공백을 삽입하는 방법은 유망한 \rowcolor{...} 방법 tabularx이지만 사용하면 안 됩니다.@{\extracolsep{\fill}}
  • 사용 시 tabularx최소한 하나의 열이 유형이어야 합니다.X
  • 모든 열의 너비가 같을 수 있는 경우 테이블의 코드는 다음과 tabularx같습니다.
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}[ht]
\centering
  \caption{Not too good looking table here.\label{tab:table1}}
  \footnotesize
    \begin{tabularx}{\textwidth}{CC|CC}
\hline
\multicolumn{2}{c|}{\textbf{Test1}} 
                    & \multicolumn{2}{c}{\textbf{Test2}}    \\
Test11  & Test12    & Test13    & Test14                    \\
    \hline
FLTR2   & 2         & 40        & FLTR0                     \\
FLTR0   & 80        & 80        & FLTR0                     \\
\rowcolor{red!30} 
\textcolor{purple}{FLTR0} 
        & \textcolor{purple}{160} 
                    &  \textcolor{purple}{204} 
                                & \textcolor{purple}{FLTR4} \\
FLTR6   & 6         & 44        & FLTR4                     \\
\rowcolor{red!30}
\textcolor{purple}{FLTR16} 
        & \textcolor{purple}{16} 
                    & \textcolor{purple}{43¸} 
                                & \textcolor{purple}{FLTR3} \\
FLTR4   & 44        & 6         & FLTR6                     \\
    \hline
    \end{tabularx}%
\end{table}

\end{document}

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

내 생각에는 이 테이블의 열 내용 사이에 빈 공간이 너무 많습니다. 테이블 너비를 줄이고 싶다면 더 좋을 것입니다.

편집하다:tabularrayMWE의 첫 번째 및 두 번째 열 너비 사용 및 패키지 에서 일부 셀에만 색상이 지정된 좁은 테이블의 예는 siunitx다음과 같습니다.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx, varwidth}
\NewTableCommand\SCC[2]{\SetCell{bg=#1, fg=#2}}

\begin{document}

    \begin{table}[ht]
    \centering
\caption{Not too good looking table here.}
\label{tab:table1}
    \begin{tblr}{colspec={Q[l] Q[c, si={table-format=3.0}] |
                          Q[c, si={table-format=3.0}] Q[l] },
                 row{1} = {font=\bfseries, guard},
                 row{2} = {guard}
                 }
    \toprule
\SetCell[c=2]{c}    Test 1
        &           & \SetCell[c=2]{c}    Test 2    
                                &                   \\
Test11  & Test12    & Test13    & Test14            \\
    \midrule
FLTR2   &   2       & 40        & FLTR0             \\
FLTR0   &   80      & 80        & FLTR0             \\
\SetRow{bg=red!20, fg=purple} 
FLTR0   &   160     &   204     &   FLTR4           \\     
FLTR6   &   6       &   44      &   FLTR4           \\
\SCC{red!20}{purple}
FLTR16  & \SCC{red!20}{purple}
            16      &   43      &   FLTR3           \\
FLTR4   &   44      &   6       & FLTR6             \\
    \bottomrule
    \end{tblr}%
\end{table}

\end{document}

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

답변2

아마도 이것이 도움이 될 것입니다. 질문을 환영합니다

MWE

\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}
\usepackage{bigstrut}
\definecolor{LightGray}{gray}{0.9}

\begin{document}
    
    \begin{NiceTabular}{c @{\extracolsep{\fill}} c|ccc}[colortbl-like]
        \toprule
    \multicolumn{2}{c|}{\textbf{Test1}} & \multicolumn{2}{c}{\textbf{Test2}} \bigstrut[t]\\
        Test11 & Test12 & Test13 & Test14 \bigstrut[b]\\
        \midrule
        FLTR2 & 2     & 40    & FLTR0 \bigstrut[t]\\
        FLTR0 & 80    & 80    & FLTR0 \\
        \rowcolor[rgb]{ 1,  .78,  .808} \textcolor[rgb]{ .612,  0,  .024}{FLTR0} & \textcolor[rgb]{ .612,  0,  .024}{160} & \textcolor[rgb]{ .612,  0,  .024}{204} & \textcolor[rgb]{ .612,  0,  .024}{FLTR4} \\
        FLTR6 & 6     & 44    & FLTR4 \\
        \rowcolor[rgb]{ 1,  .78,  .808} \textcolor[rgb]{ .612,  0,  .024}{FLTR16} & \textcolor[rgb]{ .612,  0,  .024}{16} & \cellcolor[rgb]{ 1,  1,  1}43 & \cellcolor[rgb]{ 1,  1,  1}FLTR3 \\
        FLTR4 & 44    & 6     & FLTR6 \bigstrut[b]\\
        \bottomrule
    \end{NiceTabular}
    
\end{document}

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

전체에 걸쳐 테이블을 확장하려면 다음 열과 유사한 항목을 text width제공하십시오.X columnstabularx

\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}
\usepackage{bigstrut}
\definecolor{LightGray}{gray}{0.9}

\begin{document}
    
    \begin{NiceTabular}{c X[c]|c X[c]}[colortbl-like]
        \toprule
        \multicolumn{2}{c|}{\textbf{Test1}} & \multicolumn{2}{c}{\textbf{Test2}} \bigstrut[t]\\
        Test11 & Test12 & Test13 & Test14 \bigstrut[b]\\
        \midrule
        FLTR2 & 2     & 40    & FLTR0 \bigstrut[t]\\
        FLTR0 & 80    & 80    & FLTR0 \\
        \rowcolor[rgb]{ 1,  .78,  .808} \textcolor[rgb]{ .612,  0,  .024}{FLTR0} & \textcolor[rgb]{ .612,  0,  .024}{160} & \textcolor[rgb]{ .612,  0,  .024}{204} & \textcolor[rgb]{ .612,  0,  .024}{FLTR4} \\
        FLTR6 & 6     & 44    & FLTR4 \\
        \rowcolor[rgb]{ 1,  .78,  .808} \textcolor[rgb]{ .612,  0,  .024}{FLTR16} & \textcolor[rgb]{ .612,  0,  .024}{16} & \cellcolor[rgb]{ 1,  1,  1}43 & \cellcolor[rgb]{ 1,  1,  1}FLTR3 \\
        FLTR4 & 44    & 6     & FLTR6 \bigstrut[b]\\
        \bottomrule
    \end{NiceTabular}
    
\end{document}

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

답변3

nicematrix{tabular*}를 {NiceTabular*}의 키로 바꾸면 colortbl-like다음과 같은 결과를 얻을 수 있습니다.

\documentclass{article}
\usepackage{float}
\usepackage{xcolor}
\usepackage{nicematrix}
\usepackage{bigstrut}
\definecolor{LightGray}{gray}{0.9}

\begin{document}

\begin{table}[H]
\centering
  \caption{Not too good looking table here.\label{tab:table1}}
  \footnotesize
% Table generated by Excel2LaTeX from sheet 'Sheet2'
    \begin{NiceTabular*}{\textwidth}{c @{\extracolsep{\fill}} c|ccc}[colortbl-like]
    %\begin{tabular*}{cc|cc}
    %\toprule
    \hline
    \multicolumn{2}{c|}{\textbf{Test1}} & \multicolumn{2}{c}{\textbf{Test2}} \bigstrut[t]\\
   Test11 & Test12 & Test13 & Test14 \bigstrut[b]\\
   %\midrule
    \hline
    FLTR2 & 2     & 40    & FLTR0 \bigstrut[t]\\
    FLTR0 & 80    & 80    & FLTR0 \\
    \rowcolor[rgb]{ 1,  .78,  .808} \textcolor[rgb]{ .612,  0,  .024}{FLTR0} & \textcolor[rgb]{ .612,  0,  .024}{160} & \textcolor[rgb]{ .612,  0,  .024}{204} & \textcolor[rgb]{ .612,  0,  .024}{FLTR4} \\
    FLTR6 & 6     & 44    & FLTR4 \\
    \rowcolor[rgb]{ 1,  .78,  .808} \textcolor[rgb]{ .612,  0,  .024}{FLTR16} & \textcolor[rgb]{ .612,  0,  .024}{16} & \cellcolor[rgb]{ 1,  1,  1}43 & \cellcolor[rgb]{ 1,  1,  1}FLTR3 \\
    FLTR4 & 44    & 6     & FLTR6 \bigstrut[b]\\
    \hline
    %\bottomrule
    \end{NiceTabular*}%
    %\end{tabular*}
\end{table}

\end{document}

위 코드의 출력

테이블 형식의 서문에는 5개의 열이 표시되어 있지만 4개만 사용했습니다.

관련 정보