2011-04-11 3 views
5

나는 아래 그림에 더 많거나 적은 표를 닮은 내 문서에서 테이블을 만들려고 해요 :이 테이블이 예상되는행 색상을 표 형식 (* | x)으로 교체 하시겠습니까?

Example table with alternate row coloring

\textwidth 수평으로 뻗어있다. tabular* 나의 첫 번째 시도는 다음과 같이 보았다 :

\documentclass{scrartcl} 
\usepackage[table]{xcolor} 
\definecolor{tableShade}{gray}{0.9} 

\begin{document} 
    \rowcolors{3}{tableShade}{white} %% start alternating shades from 3rd row 
    \noindent\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lrrr} 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    \end{tabular*} 
\end{document} 

결과가 있었다 :

Example table with tabular*

음, 대체 행 색상 작동하지만 열 사이 tabular* 삽입 공간을 \textwidth에 전체 테이블을 스트레칭. 내 LaTeX 동반자를 통해 브라우징하면 tabularx이 내가 원하는 것을 할 수 있어야한다는 것을 알게되었습니다. 그래서 코드를 다음과 같이 변경했습니다.

\documentclass{scrartcl} 
\usepackage[table]{xcolor} 
\usepackage{tabularx} 
\definecolor{tableShade}{gray}{0.9} 

\begin{document} 
    \rowcolors{3}{tableShade}{white} %% start alternating shades from 3rd row 
    \noindent\begin{tabularx}{\textwidth}{Xrrr} 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    \end{tabularx} 
\end{document} 

이제이 코드는 더 비슷해 보입니다. 그러나 tabularx은 채색의 시작 행을 무시하고 첫 번째 행으로 시작합니다.

Example table with tabularx

는 지금은 아이디어가 부족했습니다. 어떤 제안?

답변

6

수정 사항이 아니지만 해킹이 발생하면 \ hiderowcolors를 첫 행에 추가 한 다음 \ showrowcolors를 사용하여 색상을 다시 설정하십시오. 코드 참조 :

\rowcolors{3}{tableShade}{white} %% start alternating shades from 3rd row 
    \noindent\begin{tabularx}{\textwidth}{X X X X}%this can be {Xrrr} too 
    \hiderowcolors 
    Something & foo & bar & baz \\ 
    \showrowcolors 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
    Something & foo & bar & baz \\ 
\end{tabularx} 
+0

나는 이것이 현재 tabularx를 대체하지 않고 할 수있는 최선이라고 생각합니다. –