我在单独的文件 general.tex 中有一个包含非常长前言的文档。main.tex 看起来像
\documentclass[10pt, letterpaper]{article}
\input{general.tex}
\usepackage{subfiles}
\begin{document}
\end{document}
一般来说,我将我的主要文件设置为 Arial,并使用类似于的 ttf 文件
\setsansfont[
BoldFont=ARIAL/arialbd.ttf,
ItalicFont=ARIAL/ariali.ttf,
BoldItalicFont=ARIAL/arialbi.ttf
]{ARIAL/arial.ttf}
编译 main.tex 时,它看起来应该如此,但尝试编译子文件时,序言中的格式消失了。我不确定 general.tex 中的每个设置是否都是如此,我正在检查,但最明显的是缺少 Arial。我做错了什么,我该如何解决这个问题?非常感谢!
完整示例:general.tex
%----------------------------------------------------------------------------------------
% Packages
%----------------------------------------------------------------------------------------
% Necessary
\usepackage[german,english]{babel} % English and German language
\usepackage{booktabs} % Horizontal rules in tables
% For generating tables, use “LaTeX” online generator (https://www.tablesgenerator.com)
\usepackage{comment} % Necessary to comment several paragraphs at once
% \usepackage[utf8]{inputenc} % Required for international characters
% ^ no longer required outdated package
\usepackage[T1]{fontenc} % Required for output font encoding for international characters
% Might be helpful
\usepackage{amsmath,amsfonts,amsthm} % Math packages which might be useful for equations
\usepackage{tikz} % For tikz figures (to draw arrow diagrams, see a guide how to use them)
\usepackage{tikz-cd}
\usetikzlibrary{positioning,arrows} % Adding libraries for arrows
\usetikzlibrary{decorations.pathreplacing} % Adding libraries for decorations and paths
\usepackage{tikzsymbols} % For amazing symbols ;) https://mirror.hmc.edu/ctan/graphics/pgf/contrib/tikzsymbols/tikzsymbols.pdf
\usepackage{blindtext} % To add some blind text in your paper
\usepackage{multicol}
\usepackage{gensymb}
\usepackage{fontspec}
\setsansfont[
BoldFont=ARIAL/arialbd.ttf,
ItalicFont=ARIAL/ariali.ttf,
BoldItalicFont=ARIAL/arialbi.ttf
]{ARIAL/arial.ttf}
\usepackage{wrapfig}
% From Alex Cong
% Easy quotation marks, \say{ex.} - \say{\say{ex.}}}
\usepackage{dirtytalk}
% Easy comment large sections \bigcomment{large section}
\newcommand{\bigcomment}[1]{}
%---------------------------------------------------------------------------------
% Additional settings
%---------------------------------------------------------------------------------
%---------------------------------------------------------------------------------
% Define your margins
\usepackage{geometry} % Necessary package for defining margins
\geometry{
top=2cm, % Defines top margin
bottom=2cm, % Defines bottom margin
left=2.2cm, % Defines left margin
right=2.2cm, % Defines right margin
includehead, % Includes space for a header
%includefoot, % Includes space for a footer
%showframe, % Uncomment if you want to show how it looks on the page
}
\setlength{\parindent}{15pt} % Adjust to set you indent globally
%---------------------------------------------------------------------------------
% Define your spacing
\usepackage{setspace} % Required for spacing
% Two options:
\linespread{1.5}
%\onehalfspacing % one-half-spacing linespread
%----------------------------------------------------------------------------------------
% Define your fonts
\usepackage[T1]{fontenc} % Output font encoding for international characters}
% \usepackage[utf8]{inputenc} % Required for inputting international characters
% ^ no longer required
\usepackage{XCharter} % Use the XCharter font
%---------------------------------------------------------------------------------
% Define your headers and footers
\usepackage{fancyhdr} % Package is needed to define header and footer
\pagestyle{fancy} % Allows you to customize the headers and footers
%\renewcommand{\sectionmark}[1]{\markboth{#1}{}} % Removes the section number from the header when \leftmark is used
\pagestyle{fancy}
\fancyhf{}
\rhead{}
\lhead{2021-2022 Design Report}
\rfoot{Page \thepage}
% Headers
% \lhead{} % Define left header
% \chead{\textit{}} % Define center header - e.g. add your paper title
%\chead{}
% \rhead{} % Define right header
% Footers
% \lfoot{} % Define left footer
% \cfoot{\footnotesize \thepage} % Define center footer
% \rfoot{} % Define right footer
%---------------------------------------------------------------------------------
% Add information on bibliography
\usepackage{natbib} % Use natbib for citing
\usepackage{har2nat} % Allows to use harvard package with natbib https://mirror.reismil.ch/CTAN/macros/latex/contrib/har2nat/har2nat.pdf
% For citing with natbib, you may want to use this reference sheet:
% http://merkel.texture.rocks/Latex/natbib.php
\usepackage{pdfpages}
%---------------------------------------------------------------------------------
% Add field for signature (Reference: https://tex.stackexchange.com/questions/35942/how-to-create-a-signature-date-page)
\newcommand{\signature}[2][5cm]{%
\begin{tabular}{@{}p{#1}@{}}
#2 \\[2\normalbaselineskip] \hrule \\[0pt]
{\small \textit{Signature}} \\[2\normalbaselineskip] \hrule \\[0pt]
{\small \textit{Place, Date}}
\end{tabular}
}
主文本
%{
% Credits are indicated where needed. The general idea is based on a template by Vel ([email protected]) and Frits Wenneker.
\documentclass[10pt, letterpaper]{article} % General settings in the beginning (defines the document class of your paper)
% 10pt = is the font size
% Letter is the paper size
% “article” is your document class
%\setlength\parskip{1em plus 0.1em minus 0.2em}
% if you want automatically change spacing between paragraphs
\input{general.tex} % Loads required packages from the separate file
\usepackage{amsmath}
% \usepackage[utf8]{inputenc}
% Outdated package
\usepackage{listings}
\usepackage{xcolor,colortbl}
\usepackage{graphicx}
\usepackage{lscape}
\usepackage{float}
\floatplacement{figure}{H}
\floatplacement{table}{H}
\usepackage{caption}
\usepackage{subcaption}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
%}
%---------------------------------------------------------------------------------
% General information
%---------------------------------------------------------------------------------
\title{} % Adds your title
\author{}
% \author{Chris Hayner, Caroline Paxton, Howard Peng, Max Mcgowan % Add your first and last name
%\thanks{} % Adds a footnote to your title
%\institution{YOUR INSTITUTION} % Adds your institution
% }
% \date{December 7, 2020} % Adds the current date to your “cover” page; leave empty if you do not want to add a date
%---------------------------------------------------------------------------------
% Define what’s in your document
%---------------------------------------------------------------------------------
\setcounter{tocdepth}{2}
\setlength{\parindent}{0pt}
\usepackage[titles]{tocloft}
\usepackage{subfiles}
\begin{document}
% If you want a cover page, uncomment "\input{content/0A-coverpage}" and comment "\maketitle" as well as "\input{content/0B-disclaimer}"
%\maketitle % Print your title, author name and date; comment if you want a cover page
%\input{content/0A-coverpage} % Adds a cover page; uncomment if you want a cover page
% \input{content/0B-disclaimer} % Gives you the word count; comment if you want a cover page
%\input{content/0C-toc} % Adds a table of content; uncomment if required
% Make sure to use XeLaTeX, TeX Live version 2021
\setmainfont{Arial}
\newpage
%\includepdf[pages = {1}]{Figures/CoverPage.pdf}
\input{Content/1 - Abbreivations Figures TOC}
\subfile{Content/2 - Executive Summary}
\subfile{Content/3 - Management Summary}
\subfile{Content/4 - Conceptual Design}
\subfile{Content/5 - Preliminary Design}
\subfile{Content/6 - Detailed Design}
\subfile{Content/7 - Manufacturing Plan}
\subfile{Content/8 - Test Plan}
\subfile{Content/9 - Performance Results}
\input{Content/10-Reference.tex}
%---------------------------------------------------------------------------------
\end{document}
示例子文件 2 - 执行摘要.tex
%\section{Executive Summary}
\documentclass[../main.tex]{subfiles}
% \graphicspath{{\subfix{../images/}}}
\begin{document}
\section{Executive Summary}
\blindtext
\end{document}
答案1
经过以下更改后,我能够在 Linux(TeXlive)和 Windows(MikTeX)上排版您的文档,主文件和子文件均使用相同的类似 Arial 的无衬线字体。
移动命令
\setmainfont{Arial}
到排版主文件时将执行的位置和子文件。目前,它只对主文件执行,但对子文件忽略。将其移动到 之前
\begin{document}
或 中general.tex
。在
general.tex
,注释掉该行\usepackage{XCharter} % Use the XCharter font
在 Linux 和 Windows 这两个系统上,我都收到一条错误消息,提示与软件包发生冲突
fontspec
。考虑到您打算使用无衬线字体,而 XCharter 有衬线字体,因此可能不需要这个软件包。在我的两个系统上,都没有
ARIAL/arial*.ttf
安装字体,因此general.tex
我注释掉了以下几行\setsansfont[ BoldFont=ARIAL/arialbd.ttf, ItalicFont=ARIAL/ariali.ttf, BoldItalicFont=ARIAL/arialbi.ttf ]{ARIAL/arial.ttf}
我建议执行相同的更改,以验证主文件和子文件是否采用相同的 Arial 字体,然后根据需要重新引入字体命令(同时检查日志中的错误)。
调试:由于该subfiles
软件包增加了一层复杂性,因此,在出现错误时,首先确保子文件在没有子文件的情况下正确排版可能会有所帮助。在子文件的副本(位于同一位置)中,
\documentclass...{subfiles}
用主文件的前言(包括其命令)替换该行\documentclass
。确保路径正确;例如,在示例文档中将其替换
\input{general.tex}
为\input{../general.tex}
。
如果此副本也出现问题(此处:未使用正确的字体排版),则问题与使用无关subfiles
,而是出在其他地方。另一方面,如果修改后的副本运行没有问题,则可能是某些文件路径存在问题。请参阅文档提示如何修复它。
最后一句话:考虑不是使用subfiles
包。在许多情况下,通过在主文件中列出语句列表\input
,然后注释掉那些不应该排版的语句,它也能起到同样的作用。