更改 longtable 的特定“属性”

更改 longtable 的特定“属性”

我想为我的设置一些常规属性,longtable以便它们的顶行始终为深灰色,并且它们始终在我的页面上水平居中。我找到了一些文档longtable,但我还不知道如何理解它。如果有人能帮我,我将不胜感激。以下是一些代码,显示了我目前所取得的进展:

% Type of doc.
\documentclass[a4paper]{book}


% General packages
\usepackage[margin=1in]{geometry}
\usepackage[pdftex]{graphicx}
\usepackage[T1]{fontenc}
\usepackage{pslatex}
\usepackage[english]{babel}
\usepackage{cjhebrew}
\usepackage{parskip}
\usepackage{enumerate}


% Set for tables
\usepackage{colortbl}
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.95}

\usepackage{longtable,tabu}
\usepackage{array} % for extrarowheight
\renewcommand{\arraystretch}{1.5}



% Start doc.
\begin{document}


% Global font settings
\renewcommand{\rmdefault}{ppl}
\fontencoding{T1}
\fontfamily{ppl}
\fontsize{14}{18}
\selectfont


% Text

\chapter{Preface}

\section{Section 1}

Lots of text here.  Lots of text here.  Lots of text here.  Lots of text here.  Lots of text here.  Lots of text here.  Lots of text here.

\clearpage

\rowcolors{1}{}{lightgray}
\begin{longtable}{|p{7.5cm}|p{7.5cm}|}
\hline

\multicolumn{1}{|c}{\textbf{Col. 1}} & \multicolumn{1}{|c|}{\textbf{Col. 2}} \\ \hline

Text in Col 1. & Text in Col 2. \\ \hline
Text in Col 1. & Text in Col 2. \\ \hline
Text in Col 1. & Text in Col 2. \\ \hline
Text in Col 1. & Text in Col 2. \\ \hline
Text in Col 1. & Text in Col 2. \\ \hline

\hline
\end{longtable}


\end{document}

还询问了LaTeX 社区论坛

答案1

Longtable 默认居中,但您可以使用 将其更改为左居中或右居中\begin{longtable}[l]。在本例中,差别很小,因为宽列会强制表格全宽p,因此几乎不需要对齐表格。

就像tabular,它实际上没有任何字体和颜色的全局设置,尽管您当然可以为经常使用的表单定义自己的宏快捷方式。要获得在分页符处重复的深灰色背景上的标题,您可以执行以下操作

在此处输入图片描述

\documentclass[a4paper]{book}


% General packages
\usepackage[margin=1in]{geometry}
\usepackage[pdftex]{graphicx}
\usepackage[T1]{fontenc}
\usepackage{pslatex}
\usepackage[english]{babel}
\usepackage{cjhebrew}
\usepackage{parskip}
\usepackage{enumerate}


% Set for tables
\usepackage{colortbl}
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.95}
\definecolor{darkgray}{gray}{0.3}

\usepackage{longtable,tabu}
\usepackage{array} % for extrarowheight
\renewcommand{\arraystretch}{1.5}



% Start doc.
\begin{document}


% Global font settings
\renewcommand{\rmdefault}{ppl}
\fontencoding{T1}
\fontfamily{ppl}
\fontsize{14}{18}
\selectfont


% Text

\chapter{Preface}

\section{Section 1}

Lots of text here.  Lots of text here.  Lots of text here.  Lots of text here.  Lots of text here.  Lots of text here.  Lots of text here.

\clearpage

\rowcolors{1}{}{lightgray}
\begin{longtable}{|p{7.5cm}|p{7.5cm}|}
\hline
\rowcolor{darkgray}
\multicolumn{1}{|c}{\color{white}\textbf{Col. 1}} &
\multicolumn{1}{|c|}{\color{white}\textbf{Col. 2}} \\ \hline
\endhead
Text in Col 1. & Text in Col 2. \\ \hline
Text in Col 1. & Text in Col 2. \\ \hline
Text in Col 1. & Text in Col 2. \\ \hline
Text in Col 1. & Text in Col 2. \\ \hline
Text in Col 1. & Text in Col 2. \\ \hline

\hline
\end{longtable}


\end{document}

相关内容