![使用 fancyhdr 添加颜色标题的 utf8 问题](https://linux22.com/image/321219/%E4%BD%BF%E7%94%A8%20fancyhdr%20%E6%B7%BB%E5%8A%A0%E9%A2%9C%E8%89%B2%E6%A0%87%E9%A2%98%E7%9A%84%20utf8%20%E9%97%AE%E9%A2%98.png)
我正在制作一本诗集,我想给页面添加一些特定的样式。所以我使用fancyhdr
,一切都很顺利,直到我添加\usepackage[utf8]{inputenc}
这是我使用的代码
\documentclass{book}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{titlesec}
\input{Recursos/poem-template.tex}
% aqui definimos el encabezado de las paginas pares e impares.
\lhead[x1\begin{picture}(0,0)\put(-50,-693){\includegraphics[width=0.125in,height=11in]{Gráficos/orange.png}} \end{picture}]{x2}
\chead[y1]{y2}
\rhead[z1]{z2\begin{picture}(0,0)\put(50,-693){\includegraphics[width=0.125in,height=11in]{Gráficos/orange.png}} \end{picture}}
\renewcommand{\headrulewidth}{0pt}
% aqui definimos el encabezado y pie de pagina de la pagina inicial de un capitulo.
\fancypagestyle{plain}{
\fancyhead[L]{K1\begin{picture}(0,0)\put(-106,-75){\includegraphics[width=8.5in,height=1in]{Gráficos/orange.png}K1} \end{picture}}
\fancyhead[C]{K2}
\fancyhead[R]{K3}
\renewcommand{\headrulewidth}{0pt}
}
\pagestyle{fancy}
\begin{document}
\titleformat{\chapter}[display]
{\large\scshape\centering}{}{0pt}{\large}
\titlespacing*{\chapter}{0pt}{*0}{0pt}
\poem{Poem-sample}{dd/mm/aaaa}{poem-sample.tex}
\end{document}
这是文件poem-sample.tex
\centering
Proin laoreet
felis vitae
mollis volutpat.
In ac dolor id
nulla consectetur faucibus.
Nam ultrices mi non
quam tempor tristique.
Aenean sed urna dapibus,
hendrerit magna non,
porttitor sapien.
Vivamus sed lorem
sit amet est
scelerisque mattis.
Ut ac elit at dui
feugiat pulvinar.
Etiam efficitur
ex in facilisis porta.
Mauris viverra libero
nec justo ullamcorper,
ac laoreet odio ultrices.
Fusce in odio at erat
pharetra hendrerit.
Praesent fringilla
erat ut velit pellentesque,
nec bibendum mi lobortis.
Aliquam convallis
enim vel convallis ornare.
In molestie mauris
quis enim ornare efficitur.
Cras faucibus tellus
eu justo tincidunt varius.
Aenean vel risus
ac urna vehicula mollis
in sit amet justo.
Praesent nec nulla
id purus hendrerit
efficitur ac vel felis.
这就是poem-template.tex
\newcommand{\poem}[3]{\chapter{#1}\centering\small\textit{#2}\\[0.05in]\normalsize\verseinput{"Contenido/texto/#3"}}
\begingroup
\makeatletter
\catcode13\active%
\gdef\verseinput#1{%
{%
\interlinepenalty\@M%
\def^^M{\@ifnextchar^^M\par{\ifhmode\break\fi}}%
\rightskip\fill%
\parindent\z@%
\parskip\baselineskip%
\raggedbottom%
\catcode13\active\input{#1}%
\par%
}}%
\endgroup%
我正在使用 MiKTeX,我认为这是问题所在
答案1
我不认为添加\usepackage[utf8]{inputenc}
对于您的代码来说是个问题。
真正的问题是您的文件路径中有非 ASCII 符号,例如:Gráficos/orange.png
。
使用以下 MWE,我可以运行您的代码而不会出现错误或警告。我刚刚使用[demo]
包选项停用了图形文件的错误路径graphicx
:
\RequirePackage{filecontents}
\begin{filecontents}{poem-sample.tex}
\centering
Proin laoreet
felis vitae
mollis volutpat.
In ac dolor id
nulla consectetur faucibus.
Nam ultrices mi non
quam tempor tristique.
Aenean sed urna dapibus,
hendrerit magna non,
porttitor sapien.
Vivamus sed lorem
sit amet est
scelerisque mattis.
Ut ac elit at dui
feugiat pulvinar.
Etiam efficitur
ex in facilisis porta.
Mauris viverra libero
nec justo ullamcorper,
ac laoreet odio ultrices.
Fusce in odio at erat
pharetra hendrerit.
Praesent fringilla
erat ut velit pellentesque,
nec bibendum mi lobortis.
Aliquam convallis
enim vel convallis ornare.
In molestie mauris
quis enim ornare efficitur.
Cras faucibus tellus
eu justo tincidunt varius.
Aenean vel risus
ac urna vehicula mollis
in sit amet justo.
Praesent nec nulla
id purus hendrerit
efficitur ac vel felis.
\end{filecontents}
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[demo]{graphicx}
\usepackage{fancyhdr}
\usepackage{titlesec}
\newcommand{\poem}[3]{\chapter{#1}\centering\small\textit{#2}\\[0.05in]\normalsize\verseinput{"#3"}}% <==============================
\begingroup
\makeatletter
\catcode13\active%
\gdef\verseinput#1{%
{%
\interlinepenalty\@M%
\def^^M{\@ifnextchar^^M\par{\ifhmode\break\fi}}%
\rightskip\fill%
\parindent\z@%
\parskip\baselineskip%
\raggedbottom%
\catcode13\active\input{#1}%
\par%
}}%
\endgroup%
% aqui definimos el encabezado de las paginas pares e impares.
\lhead[x1\begin{picture}(0,0)\put(-50,-693){\includegraphics[width=0.125in,height=11in]{Gráficos/orange.png}} \end{picture}]{x2}
\chead[y1]{y2}
\rhead[z1]{z2\begin{picture}(0,0)\put(50,-693){\includegraphics[width=0.125in,height=11in]{Gráficos/orange.png}} \end{picture}}
\renewcommand{\headrulewidth}{0pt}
% aqui definimos el encabezado y pie de pagina de la pagina inicial de un capitulo.
\fancypagestyle{plain}{
\fancyhead[L]{K1\begin{picture}(0,0)\put(-106,-75){\includegraphics[width=8.5in,height=1in]{Gráficos/orange.png}K1} \end{picture}}
\fancyhead[C]{K2}
\fancyhead[R]{K3}
\renewcommand{\headrulewidth}{0pt}
}
\pagestyle{fancy}
\begin{document}
\titleformat{\chapter}[display]
{\large\scshape\centering}{}{0pt}{\large}
\titlespacing*{\chapter}{0pt}{*0}{0pt}
\poem{Poem-sample}{dd/mm/aaaa}{poem-sample.tex}
\end{document}
结果:
请注意我改变了你的命令\poem
:
\newcommand{\poem}[3]{\chapter{#1}\centering\small\textit{#2}\\[0.05in]\normalsize\verseinput{"#3"}}% <==============================