![如何在第一页正确包含标题图像](https://linux22.com/image/309369/%E5%A6%82%E4%BD%95%E5%9C%A8%E7%AC%AC%E4%B8%80%E9%A1%B5%E6%AD%A3%E7%A1%AE%E5%8C%85%E5%90%AB%E6%A0%87%E9%A2%98%E5%9B%BE%E5%83%8F.png)
我发现了一个不错的 Latex 模板这里我想在标题中添加一个与右侧对齐的图像。我喜欢这个模板,所以我想对其进行调整。
我添加了一张蓝色测试图片用于演示。接下来的页面中,第一页页眉所占的空间在第二页中被包含为空白。我在图片中用红色矩形标记了此空间。请注意,在文档中,此空间仅为白色。
如何包含图像并从第二页中删除空白?我尝试引入pagestyles
,fancy header
但它不起作用。
\fancypagestyle{firststyle}
{
\fancyhf{}
\rhead{\raisebox{-2.2\height}{\includegraphics[height=30mm]{testimage}}}
}
\fancypagestyle{second}{%
\fancyhead{}
}
使用所述的两种页面样式这里效果不如预期,第二种样式没有任何效果。要么图片被移除,要么空间被占用。你可以查看下面的完整源代码并尝试一下见下页。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Large Colored Title Article
% LaTeX Template
% Version 1.1 (25/11/12)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% Original author:
% Frits Wenneker (http://www.howtotex.com)
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[DIV=calc, paper=a4, fontsize=11pt, twocolumn]{scrartcl} % A4 paper and 11pt font size
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage[english]{babel} % English language/hyphenation
\usepackage[utf8]{inputenc}
\usepackage[protrusion=true,expansion=true]{microtype} % Better typography
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage[svgnames,dvipsnames]{xcolor} % Enabling colors by their 'svgnames'
\usepackage[hang, small,labelfont=bf,up,textfont=it,up]{caption} % Custom captions under/above floats in tables or figures
\usepackage{booktabs} % Horizontal rules in tables
\usepackage{fix-cm} % Custom font sizes - used for the initial letter in the document
\usepackage{framed, color}
\usepackage{url}
%%%%%%%%%%%%%%%%% Farbige box
\usepackage{tcolorbox}
%%%%%%%%%%%%%%%%%
\usepackage{sectsty} % Enables custom section titles
\allsectionsfont{\usefont{OT1}{phv}{b}{n}} % Change the font of all section commands
\usepackage{fancyhdr} % Needed to define custom headers/footers
\pagestyle{fancy} % Enables the custom headers/footers
\usepackage{lastpage} % Used to determine the number of pages in the document (for "Page X of Total")
% Headers - all currently empty
\lhead{}
\chead{}
\rhead{}
% Footers
\lfoot{}
\cfoot{}
\rfoot{\footnotesize Page \thepage\ of \pageref{LastPage}} % "Page 1 of 2"
\renewcommand{\headrulewidth}{0.0pt} % No header rule
\renewcommand{\footrulewidth}{0.4pt} % Thin footer rule
\usepackage{lettrine} % Package to accentuate the first letter of the text
\newcommand{\initial}[1]{ % Defines the command and style for the first letter
\lettrine[lines=3,lhang=0.3,nindent=0em]{
\color{OliveGreen}
{\textsf{#1}}}{}}
%----------------------------------------------------------------------------------------
% TITLE SECTION
%----------------------------------------------------------------------------------------
\usepackage{titling} % Allows custom title configuration
\newcommand{\HorRule}{\color{OliveGreen} \rule{\linewidth}{1pt}} % Defines the gold horizontal rule around the title
\pretitle{\vspace{-30pt} \begin{flushleft} \HorRule \fontsize{50}{50} \usefont{OT1}{phv}{b}{n} \color{RawSienna} \selectfont} % Horizontal rule before the title
\title{Test Article} % Your article title
\posttitle{\par\end{flushleft}\vskip 0.5em} % Whitespace under the title
\preauthor{\begin{flushleft}\large \lineskip 0.5em \usefont{OT1}{phv}{b}{sl} \color{Black}} % Author font configuration
\author{John Doe\\} % Your name
\postauthor{\footnotesize \usefont{OT1}{phv}{m}{sl} \color{Black} % Configuration for the institution name
Sample Institute of Technology\\
% Your institution
%% logo
%\rhead{\raisebox{-2.0\height}{\includegraphics[height=40mm]{images/logo2}}}
\par\end{flushleft}\HorRule} % Horizontal rule after the title
\date{\today} % Add a date here if you would like one to appear underneath the title block
%----------------------------------------------------------------------------------------
\fancypagestyle{firststyle}
{
\fancyhf{}
\rhead{\raisebox{-2.2\height}{\includegraphics[height=30mm]{testimage}}}
}
\fancypagestyle{second}{%
\fancyhead{}
}
\begin{document}
\maketitle % Print the title
\thispagestyle{firststyle} % Enabling the custom headers/footers for the first page
%----------------------------------------------------------------------------------------
% ABSTRACT
%----------------------------------------------------------------------------------------
% The first character should be within \initial{}
\textbf{\lipsum[1-2]}
%----------------------------------------------------------------------------------------
% ARTICLE CONTENTS
%----------------------------------------------------------------------------------------
\section*{Section 1}
\lipsum[1-4]
\section*{Section 2}
\lipsum[1-4]
\thispagestyle{second} % Enabling the custom headers/footers for the first page
\section*{Section 2}
\lipsum[1-4]
%----------------------------------------------------------------------------------------
\end{document}
答案1
从下往上叠加图像和从上往下叠加图像同样有意义。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Large Colored Title Article
% LaTeX Template
% Version 1.1 (25/11/12)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% Original author:
% Frits Wenneker (http://www.howtotex.com)
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[DIV=calc, paper=a4, fontsize=11pt, twocolumn]{scrartcl} % A4 paper and 11pt font size
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage[english]{babel} % English language/hyphenation
\usepackage[utf8]{inputenc}
\usepackage[protrusion=true,expansion=true]{microtype} % Better typography
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage[svgnames,dvipsnames]{xcolor} % Enabling colors by their 'svgnames'
\usepackage[hang, small,labelfont=bf,up,textfont=it,up]{caption} % Custom captions under/above floats in tables or figures
\usepackage{booktabs} % Horizontal rules in tables
\usepackage{fix-cm} % Custom font sizes - used for the initial letter in the document
\usepackage{framed, color}
\usepackage{url}
%%%%%%%%%%%%%%%%% Farbige box
\usepackage{tcolorbox}
%%%%%%%%%%%%%%%%%
\usepackage{sectsty} % Enables custom section titles
\allsectionsfont{\usefont{OT1}{phv}{b}{n}} % Change the font of all section commands
\usepackage{fancyhdr} % Needed to define custom headers/footers
\pagestyle{fancy} % Enables the custom headers/footers
\usepackage{lastpage} % Used to determine the number of pages in the document (for "Page X of Total")
\usepackage{mwe}% for example-image
% Headers - all currently empty
\lhead{}
\chead{}
\rhead{}
% Footers
\lfoot{}
\cfoot{}
\rfoot{\footnotesize Page \thepage\ of \pageref{LastPage}} % "Page 1 of 2"
\renewcommand{\headrulewidth}{0.0pt} % No header rule
\renewcommand{\footrulewidth}{0.4pt} % Thin footer rule
\usepackage{lettrine} % Package to accentuate the first letter of the text
\newcommand{\initial}[1]{ % Defines the command and style for the first letter
\lettrine[lines=3,lhang=0.3,nindent=0em]{
\color{OliveGreen}
{\textsf{#1}}}{}}
%----------------------------------------------------------------------------------------
% TITLE SECTION
%----------------------------------------------------------------------------------------
\usepackage{titling} % Allows custom title configuration
\newcommand{\HorRule}{\color{OliveGreen} \rule{\linewidth}{1pt}} % Defines the gold horizontal rule around the title
\pretitle{\vspace{-30pt} \begin{flushleft} \HorRule \fontsize{50}{50} \usefont{OT1}{phv}{b}{n} \color{RawSienna} \selectfont} % Horizontal rule before the title
\title{Test Article} % Your article title
\posttitle{\par\end{flushleft}\vskip 0.5em} % Whitespace under the title
\preauthor{\begin{flushleft}\large \lineskip 0.5em \usefont{OT1}{phv}{b}{sl} \color{Black}} % Author font configuration
\author{John Doe\\} % Your name
\postauthor{\footnotesize \usefont{OT1}{phv}{m}{sl} \color{Black} % Configuration for the institution name
Sample Institute of Technology\\
% Your institution
%% logo
%\rhead{\raisebox{-2.0\height}{\includegraphics[height=40mm]{images/logo2}}}
\par\end{flushleft}\HorRule} % Horizontal rule after the title
\date{\today} % Add a date here if you would like one to appear underneath the title block
%----------------------------------------------------------------------------------------
\begin{document}
\maketitle % Print the title
\noindent\raisebox{29mm}[0pt][0pt]{\rlap{\makebox[\textwidth][r]{\includegraphics[height=30mm]{example-image}}}}
%----------------------------------------------------------------------------------------
% ABSTRACT
%----------------------------------------------------------------------------------------
% The first character should be within \initial{}
\textbf{\lipsum[1-2]}
%----------------------------------------------------------------------------------------
% ARTICLE CONTENTS
%----------------------------------------------------------------------------------------
\section*{Section 1}
\lipsum[1-4]
\section*{Section 2}
\lipsum[1-4]
\section*{Section 3}
\lipsum[1-4]
%----------------------------------------------------------------------------------------
\end{document}
答案2
有很多种可能性,以下是其中两种
.
.
.
.
%--- one way
%\usepackage{eso-pic}
%\newcommand\AtPageUpperMyright[1]{\AtPageUpperLeft{%
% \put(\LenToUnit{0.7\paperwidth},\LenToUnit{-5.7cm}){%
% \parbox{0.26055\textwidth}{\raggedleft#1}}%
% }}%
%\newcommand{\mylogo}[1]{%
%\AddToShipoutPictureBG*{%
%\AtPageUpperMyright{#1}
%}
%}
%%-- another way
\usepackage{tikzpagenodes}
\newcommand{\mylogo}[1]{%
\tikz[remember picture,overlay] {%
\node[inner sep=0pt,anchor=east] at ([yshift=-4.05cm]current page text area.north east){#1};}
}
\begin{document}
\maketitle % Print the title
\mylogo{\includegraphics[height=30mm]{example-image-a}}
.
.
.
.
.
tikzpagenodes
方式至少需要2-3次编译运行才能稳定下来。
完整代码:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Large Colored Title Article
% LaTeX Template
% Version 1.1 (25/11/12)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% Original author:
% Frits Wenneker (http://www.howtotex.com)
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[DIV=calc, paper=a4, fontsize=11pt, twocolumn]{scrartcl} % A4 paper and 11pt font size
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage[english]{babel} % English language/hyphenation
\usepackage[utf8]{inputenc}
\usepackage[protrusion=true,expansion=true]{microtype} % Better typography
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage[svgnames,dvipsnames]{xcolor} % Enabling colors by their 'svgnames'
\usepackage[hang, small,labelfont=bf,up,textfont=it,up]{caption} % Custom captions under/above floats in tables or figures
\usepackage{booktabs} % Horizontal rules in tables
\usepackage{fix-cm} % Custom font sizes - used for the initial letter in the document
\usepackage{framed, color}
\usepackage{url}
%%%%%%%%%%%%%%%%% Farbige box
\usepackage{tcolorbox}
%%%%%%%%%%%%%%%%%
\usepackage{sectsty} % Enables custom section titles
\allsectionsfont{\usefont{OT1}{phv}{b}{n}} % Change the font of all section commands
\usepackage{fancyhdr} % Needed to define custom headers/footers
\pagestyle{fancy} % Enables the custom headers/footers
\usepackage{lastpage} % Used to determine the number of pages in the document (for "Page X of Total")
% Headers - all currently empty
\lhead{}
\chead{}
\rhead{}
% Footers
\lfoot{}
\cfoot{}
\rfoot{\footnotesize Page \thepage\ of \pageref{LastPage}} % "Page 1 of 2"
\renewcommand{\headrulewidth}{0.0pt} % No header rule
\renewcommand{\footrulewidth}{0.4pt} % Thin footer rule
\usepackage{lettrine} % Package to accentuate the first letter of the text
\newcommand{\initial}[1]{ % Defines the command and style for the first letter
\lettrine[lines=3,lhang=0.3,nindent=0em]{
\color{OliveGreen}
{\textsf{#1}}}{}}
%----------------------------------------------------------------------------------------
% TITLE SECTION
%----------------------------------------------------------------------------------------
\usepackage{titling} % Allows custom title configuration
\newcommand{\HorRule}{\color{OliveGreen} \rule{\linewidth}{1pt}} % Defines the gold horizontal rule around the title
\pretitle{\vspace{-30pt} \begin{flushleft} \HorRule \fontsize{50}{50} \usefont{OT1}{phv}{b}{n} \color{RawSienna} \selectfont} % Horizontal rule before the title
\title{Test Article} % Your article title
\posttitle{\par\end{flushleft}\vskip 0.5em} % Whitespace under the title
\preauthor{\begin{flushleft}\large \lineskip 0.5em \usefont{OT1}{phv}{b}{sl} \color{Black}} % Author font configuration
\author{John Doe\\} % Your name
\postauthor{\footnotesize \usefont{OT1}{phv}{m}{sl} \color{Black} % Configuration for the institution name
Sample Institute of Technology\\
% Your institution
%% logo
%\rhead{\raisebox{-2.0\height}{\includegraphics[height=40mm]{images/logo2}}}
\par\end{flushleft}\HorRule} % Horizontal rule after the title
\date{\today} % Add a date here if you would like one to appear underneath the title block
%----------------------------------------------------------------------------------------
%--- one way
%\usepackage{eso-pic}
%\newcommand\AtPageUpperMyright[1]{\AtPageUpperLeft{%
% \put(\LenToUnit{0.7\paperwidth},\LenToUnit{-5.7cm}){%
% \parbox{0.26055\textwidth}{\raggedleft#1}}%
% }}%
%\newcommand{\mylogo}[1]{%
%\AddToShipoutPictureBG*{%
%\AtPageUpperMyright{#1}
%}
%}
%%-- another way
\usepackage{tikzpagenodes}
\newcommand{\mylogo}[1]{%
\tikz[remember picture,overlay] {%
\node[inner sep=0pt,anchor=east] at ([yshift=-4.05cm]current page text area.north east){#1};}
}
\begin{document}
\maketitle % Print the title
\mylogo{\includegraphics[height=30mm]{example-image-a}}
%\thispagestyle{firststyle} % Enabling the custom headers/footers for the first page
%----------------------------------------------------------------------------------------
% ABSTRACT
%----------------------------------------------------------------------------------------
% The first character should be within \initial{}
\textbf{\lipsum[1-2]}
%----------------------------------------------------------------------------------------
% ARTICLE CONTENTS
%----------------------------------------------------------------------------------------
\section*{Section 1}
\lipsum[1-4]
\section*{Section 2}
\lipsum[1-4]
%\thispagestyle{second} % Enabling the custom headers/footers for the first page
\section*{Section 2}
\lipsum[1-4]
%----------------------------------------------------------------------------------------
\end{document}
附注:您有一些包,它们并不理想地与 koma 类一起使用,例如sectsty
。koma 类有自己的方式来提供这些功能。
答案3
我理解所需的图像只应出现在标题内,因此以下解决方案利用包\maketitlehook
中的命令titling
在两个垂直居中的小页面内构建标题,一个用于标题和作者,另一个用于图像。这样就无需设置不同的页面样式。
\maketitle
titling
命令由类似包重新定义
\renewcommand{\maketitle}{%
\vspace*{\droptitle}
\maketitlehooka
{\pretitle \title \posttitle}
\maketitlehookb
{\preauthor \author \postauthor}
\maketitlehookc
{\predate \date \postdate}
\maketitlehookd
}
\maketitlehook{a|b|c|d}´ are initially defined as empty commands but can be used to introduce more formatting options. In this case,
\maketitlehooka` 用于绘制顶部规则并启动一个小页面,其中将写入标题和作者
\renewcommand{\maketitlehooka}{\HorRule\\[2ex]\begin{minipage}[c]{.7\linewidth}}
\maketitlehookc
用于关闭左侧小页面并创建放置图形的右侧小页面:
\renewcommand{\maketitlehookc}{\end{minipage}\begin{minipage}[c]{.3\linewidth}%
\includegraphics[width=\textwidth]{example-image}%
\end{minipage}\\[2ex]\HorRule}
在上一个命令中,example-image
必须用所需的命令替换。规则和标题之间的间距([2ex]
)以及小页面宽度也可以根据需要进行调整。
结果如下:
完整代码如下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Large Colored Title Article
% LaTeX Template
% Version 1.1 (25/11/12)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% Original author:
% Frits Wenneker (http://www.howtotex.com)
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[DIV=calc, paper=a4, fontsize=11pt, twocolumn]{scrartcl} % A4 paper and 11pt font size
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage[english]{babel} % English language/hyphenation
\usepackage[utf8]{inputenc}
\usepackage[protrusion=true,expansion=true]{microtype} % Better typography
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage[svgnames,dvipsnames]{xcolor} % Enabling colors by their 'svgnames'
\usepackage[hang, small,labelfont=bf,up,textfont=it,up]{caption} % Custom captions under/above floats in tables or figures
\usepackage{booktabs} % Horizontal rules in tables
\usepackage{fix-cm} % Custom font sizes - used for the initial letter in the document
\usepackage{framed, color}
\usepackage{url}
%%%%%%%%%%%%%%%%% Farbige box
\usepackage{tcolorbox}
%%%%%%%%%%%%%%%%%
\usepackage{sectsty} % Enables custom section titles
\allsectionsfont{\usefont{OT1}{phv}{b}{n}} % Change the font of all section commands
\usepackage{fancyhdr} % Needed to define custom headers/footers
\pagestyle{fancy} % Enables the custom headers/footers
\usepackage{lastpage} % Used to determine the number of pages in the document (for "Page X of Total")
% Headers - all currently empty
\lhead{}
\chead{}
\rhead{}
% Footers
\lfoot{}
\cfoot{}
\rfoot{\footnotesize Page \thepage\ of \pageref{LastPage}} % "Page 1 of 2"
\renewcommand{\headrulewidth}{0.0pt} % No header rule
\renewcommand{\footrulewidth}{0.4pt} % Thin footer rule
\usepackage{lettrine} % Package to accentuate the first letter of the text
\newcommand{\initial}[1]{ % Defines the command and style for the first letter
\lettrine[lines=3,lhang=0.3,nindent=0em]{
\color{OliveGreen}
{\textsf{#1}}}{}}
%----------------------------------------------------------------------------------------
% TITLE SECTION
%----------------------------------------------------------------------------------------
\usepackage{titling} % Allows custom title configuration
\newcommand{\HorRule}{\color{OliveGreen} \rule{\linewidth}{1pt}} % Defines the gold horizontal rule around the title
\setlength{\droptitle}{30pt}
\renewcommand{\maketitlehooka}{\HorRule\\[2ex]
\begin{minipage}[c]{.7\linewidth}}
\renewcommand{\maketitlehookc}{\end{minipage}\begin{minipage}[c]{.3\linewidth}\includegraphics[width=\textwidth]{example-image}\end{minipage}\\[2ex]\HorRule}
\pretitle{\begin{flushleft}\fontsize{50}{50} \usefont{OT1}{phv}{b}{n} \color{RawSienna} \selectfont} % Horizontal rule before the title
\title{Test Article} % Your article title
\posttitle{\par\end{flushleft}\vskip 0.5em} % Whitespace under the title
\preauthor{\begin{flushleft}\large \lineskip 0.5em \usefont{OT1}{phv}{b}{sl} \color{Black}} % Author font configuration
\author{John Doe\\} % Your name
\postauthor{\footnotesize \usefont{OT1}{phv}{m}{sl} \color{Black} % Configuration for the institution name
Sample Institute of Technology\\
% Your institution
%% logo
%\rhead{\raisebox{-2.0\height}{\includegraphics[height=40mm]{images/logo2}}}
\end{flushleft}} % Horizontal rule after the title
\date{\today} % Add a date here if you would like one to appear underneath the title block
%----------------------------------------------------------------------------------------
%\fancypagestyle{firststyle}
%{
% \fancyhf{}
%% \rhead{\raisebox{-2.2\height}{\includegraphics[height=30mm]{example-image}}}
%}
%\fancypagestyle{second}{%
\fancyhead{}
%}
\begin{document}
\maketitle % Print the title
%\thispagestyle{firststyle} % Enabling the custom headers/footers for the first page
%----------------------------------------------------------------------------------------
% ABSTRACT
%----------------------------------------------------------------------------------------
% The first character should be within \initial{}
\textbf{\lipsum[1-2]}
%----------------------------------------------------------------------------------------
% ARTICLE CONTENTS
%----------------------------------------------------------------------------------------
\section*{Section 1}
\lipsum[1-4]
\section*{Section 2}
\lipsum[1-4]
%\thispagestyle{second} % Enabling the custom headers/footers for the first page
\section*{Section 2}
\lipsum[1-4]
%----------------------------------------------------------------------------------------
\end{document}