长表(longtabu)和字体样式问题

长表(longtabu)和字体样式问题

我使用longtabu环境来将表格扩展到多个页面。这种方法效果很好,但是,我总是更改字体大小和类型,如我的示例所示。这种方法也非常有效,直到我尝试将长表格和新字体样式结合起来。我总是将字体定义放在环境内table但环境外tabu,因为 latex 在环境内时总是会抛出错误tabu。所以,我想,你已经看到我的问题了。环境longtabu在环境中不起作用table,但我无法将字体定义放在环境中longtabu。有办法吗?我可以在周围创建一个框吗longtabu?问题是,当我不将字体定义放在环境中时table,该表格之后的所有文本都会获得相同的字体。这是我的代码:

\documentclass[10pt,DIV=12,a4paper,numbers=noenddot]{scrreprt}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{tabu}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{booktabs}

\usepackage{adjustbox}
\usepackage{tabularx}
\usepackage{anyfontsize}

\newcommand{\changefont}[3]{\fontfamily{#1} \fontseries{#2} \fontshape{#3} \selectfont}

\begin{document}

\begin{table}

\changefont{phv}{m}{n} % Change font to Helvetica

\fontsize{6}{9} \selectfont{ % Change font size and line spacing to 6 and 9 respectively

\begin{longtabu}{ll}

Longtable & Longtable \\
Longtable & Longtable \\
Longtable & Longtable \\
Longtable & Longtable \\
Longtable & Longtable \\

\end{longtabu}

}

\caption{This is a caption}

\end{table}

%% New example code
{

\changefont{phv}{m}{n}

\fontsize{6}{9} \selectfont

\begin{longtabu}{ll}

\toprule

\rowfont{\bfseries\itshape}

Longtable & Longtable \\
Longtable & Longtable \\
Longtable & Longtable \\
Longtable & Longtable \\
Longtable & Longtable \\

\bottomrule

\end{longtabu}

}

This is text after the long table and shoud be in standard latex format again. Apparently, it is not as you can see from
the baseline stretch which seems not to be 1.2. However, the font type seems to be ok.

\end{document}

答案1

longtabu在环境中使用Atable没有意义,因为table无法跨页面拆分。你不太清楚自己想要实现什么。不过,定义一个新的环境可能是解决方案。

\documentclass[10pt,DIV=12,a4paper,numbers=noenddot]{scrreprt}

\usepackage{tabu}
\usepackage{longtable}
\usepackage{etoolbox}

\linespread{1.2}

\makeatletter
\newcommand{\changefont}[3]{\usefont{\f@encoding}{#1}{#2}{#3}}
\patchcmd{\LT@makecaption}{\hss}{\hss\normalfont\normalsize}{}{}
\makeatother
\newenvironment{myfont}[6][1]
  {\par\linespread{#1}\fontsize{#5}{#6}\changefont{#2}{#3}{#4}}
  {\par}

\begin{document}

\begin{myfont}{phv}{m}{n}{6}{9} % Change font to Helvetica
\begin{longtabu}{ll}

Longtable & Longtable \\
Longtable & Longtable \\
Longtable & Longtable \\
Longtable & Longtable \\
Longtable & Longtable \\
\caption{This is a caption}
\end{longtabu}
\end{myfont}

This is text after the long table and shoud be in standard latex format again. Apparently, 
it is not as you can see from the baseline stretch which seems not to be 1.2. However, the 
font type seems to be ok.

\end{document}

注意使用\linespread{1.2}而不是\renewcommand{\baselinestretch}{1.2}。但是最好使用setspace包及其\setstretch{1.2}命令。

\changefont我使用标准命令以可能更清晰的方式重新定义了您的命令\usefont\f@encoding存储在当前编码中。

myfont环境可以在任何地方使用。它有五个强制参数:family、series、shape、size 和 baselineskip,以及一个初始可选参数,即基线拉伸(默认值为 1)。

我还修补了\captiona 中的命令longtable(或longtabu使用相同的命令),以便它以正常字体和大小排版。

在此处输入图片描述

相关内容