添加填充颜色的框并在其中放置大文本

添加填充颜色的框并在其中放置大文本

我正在为我的大学杂志和文章准备一堂课。我想知道如何在第一页的顶部边缘放置一个黑框,并在里面用白色写一些大文本。文档的当前样式如下所示,

% DOCUMENT LAYOUT
\documentclass[10pt, a4paper]{article}
\usepackage[left=5cm,right=2.5cm,top=5cm,bottom=3cm]{geometry}
\usepackage{fontspec}
\usepackage{marvosym}
\usepackage{wasysym}
% DOCUMENT LAYOUT
\setlength\parindent{0cm}
\usepackage[libertine={Ligatures=TeX,Numbers=OldStyle}]{libertineotf}
\setsansfont{Segoe UI}
% FONTS
\usepackage[usenames,dvipsnames]{color}
\usepackage{xunicode}
\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage{eso-pic}

% ---- CUSTOM COMMANDS
\chardef\&="E050
\newcommand{\html}[1]{\href{#1}{\scriptsize\textsc{[html]}}}
\newcommand{\pdf}[1]{\href{#1}{\scriptsize\textsc{[pdf]}}}
\newcommand{\doi}[1]{\href{#1}{\scriptsize\textsc{[doi]}}}
% ---- MARGIN YEARS
\usepackage{marginnote}
\newcommand{\amper{}}{\chardef\amper="E0BD }
\newcommand{\sides}[1]{\marginnote{\color{MidnightBlue}\sffamily #1}}
%\newcommand{\years}[1]{\marginnote{\footnotesize #1}}
%\renewcommand*{\raggedleftmarginnote}{}
\setlength{\marginparsep}{0.5cm}
\reversemarginpar

% HEADINGS
\usepackage{sectsty} 
\usepackage[normalem]{ulem} 
\sectionfont{\mdseries\upshape\Large}
\subsectionfont{\mdseries\scshape\normalsize} 
\subsubsectionfont{\mdseries\upshape\large}
\usepackage{lipsum}
\usepackage{tikz}
% PDF SETUP
\usepackage[bookmarks, colorlinks, breaklinks, 
    pdftitle={Here there},
    pdfauthor={My name},
    pdfproducer={}
]{hyperref}  
\hypersetup{linkcolor=blue,citecolor=blue,filecolor=black,urlcolor=MidnightBlue}
% DOCUMENT
\begin{document}
{\LARGE Effect of aspect ratio and others on others and ourselves}\\[3pt]
\textit{Me myself \& You}. Corr. author : \href{mailto:[email protected]}{\textit{[email protected]}}\\
\textit{Department of Mechanical Engineering.}\\[0.5cm]
{\large \bf Abstract}\\[4pt]
\lipsum[25]
{\section*{Introduction}}
\sides{I am hoping to create some proper paper using this template when i do my masters.}
\lipsum
\sides{How does a para look with this on sides. For a moment i thought it is gone}
\lipsum

%\vspace{1cm}
\vfill{}
%\hrulefill

\end{document}

有人能建议怎么做吗?我想要像右边那样的东西。 在此处输入图片描述

答案1

您的 有问题xcolor。您需要使用选项dvipsnames来使用颜色 MidnightBlue。您不需要加载,color 因为xcolor加载colorpgfplots加载tikz,您需要xcolor在 pgfplots 之前加载。

您需要编译两次下面的代码。我使用 tikz 在第一页上放置了一个黑色矩形。

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode   
  % DOCUMENT LAYOUT
\documentclass[10pt, a4paper]{article}
\usepackage[left=5cm,right=2.5cm,top=5cm,bottom=3cm]{geometry}
\usepackage{fontspec}
\usepackage{marvosym}
\usepackage{wasysym}
% DOCUMENT LAYOUT
\setlength\parindent{0cm}
\usepackage[libertine={Ligatures=TeX,Numbers=OldStyle}]{libertineotf}
%\setsansfont{Segoe UI} 
\usepackage[dvipsnames]{xcolor} 
% FONTS
\usepackage{xunicode}
\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\usepackage{pgfplots}

\usepackage{eso-pic}

% ---- CUSTOM COMMANDS
\chardef\&="E050
\newcommand{\html}[1]{\href{#1}{\scriptsize\textsc{[html]}}}
\newcommand{\pdf}[1]{\href{#1}{\scriptsize\textsc{[pdf]}}}
\newcommand{\doi}[1]{\href{#1}{\scriptsize\textsc{[doi]}}}
% ---- MARGIN YEARS
\usepackage{marginnote}
\newcommand{\amper{}}{\chardef\amper="E0BD }
\newcommand{\sides}[1]{\marginnote{\color{MidnightBlue}\sffamily #1}}
%\newcommand{\years}[1]{\marginnote{\footnotesize #1}}
%\renewcommand*{\raggedleftmarginnote}{}
\setlength{\marginparsep}{0.5cm}
\reversemarginpar

% HEADINGS
\usepackage{sectsty} 
\usepackage[normalem]{ulem} 
\sectionfont{\mdseries\upshape\Large}
\subsectionfont{\mdseries\scshape\normalsize} 
\subsubsectionfont{\mdseries\upshape\large}
\usepackage{lipsum}
%\usepackage{tikz}
% PDF SETUP
\usepackage[bookmarks, colorlinks, breaklinks, 
    pdftitle={Here there},
    pdfauthor={My name},
    pdfproducer={}
]{hyperref}  
\hypersetup{linkcolor=blue,citecolor=blue,filecolor=black,urlcolor=MidnightBlue}
% DOCUMENT 


\begin{document}
  \thispagestyle{empty} 
  \begin{tikzpicture}[remember picture,overlay]
  \node[anchor=north west,minimum width=21cm,minimum height=8cm,fill=black,text=white] (RB) at (current page.north west){\Huge TITLE};
\node[text=white,text width=4cm,anchor=north west] at ([shift={(3cm,2cm)}]RB.south west){\emph{Petit texte afin de tester la métode. Petit texte afin de tester la métode. Petit texte afin de tester la métode.}};
\end{tikzpicture}

\vspace*{10cm}
\lipsum[1]
\newpage 
{\LARGE Effect of aspect ratio and others on others and ourselves}\\[3pt]
\textit{Me myself \& You}. Corr. author : \href{mailto:[email protected]}{\textit{[email protected]}}\\
\textit{Department of Mechanical Engineering.}\\[0.5cm]
{\large \bf Abstract}\\[4pt]
\lipsum[25]
{\section*{Introduction}}
\sides{I am hoping to create some proper paper using this template when i do my masters.}
\lipsum
\sides{How does a para look with this on sides. For a moment i thought it is gone}
\lipsum

%\vspace{1cm}
\vfill{}
%\hrulefill

\end{document} 

在此处输入图片描述

答案2

您可以使用fancyhdr\colorbox在标题中放置:

在此处输入图片描述

\documentclass[10pt, a4paper]{article}
\usepackage[left=5cm,right=2.5cm,top=5cm,bottom=3cm,headheight=22pt]{geometry}% http://ctan.org/pkg/geometry
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\fancypagestyle{unique}{%
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \fancyhf{}% Clear header/footer
  \fancyfoot[C]{\thepage}%
  \fancyhead[C]{%
    \colorbox{black}{\parbox{\dimexpr\textwidth-2\fboxsep}{%
      \color{white}\LARGE Effect of aspect ratio and others on others and ourselves}}%
  }%
}
\begin{document}

\thispagestyle{unique}
\lipsum[1-10]

\end{document}

当然,您可以unique根据自己的喜好修改页面样式。我只是复制了plain页面样式并添加了所需的页眉。

对标题的修改可能包括拉伸框以跨越边距。以下是对此进行标题更改的快速查看:

\fancypagestyle{unique}{%
  \fancyhf{}% Clear header/footer
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \fancyfoot[C]{\thepage}%
  \fancyhead[C]{%
    \makebox[\textwidth]{%
      \colorbox{black}{\parbox{\dimexpr\textwidth+50pt-2\fboxsep}{%
        \color{white}\LARGE Effect of aspect ratio and others on others and ourselves}}%
  }}%
}

上述标题更改将彩色框向外(左和右)推 25 点。它通过将50pt重叠的彩色框放在居中的\textwidth框内来实现这一点。这避免了 LaTeX 抱怨溢出\hbox超过\textwidth

答案3

tcolorbox一:我们可以使用Thomas F. Sturm提供的包。

像书中一样制作一个示例和阴影框

二:我们可以使用包轮廓

\documentclass{standalone}

\usepackage{tikz}
\usepackage[outline]{contour}
\contourlength{1.2pt}

\begin{document}

\begin{tikzpicture}[scale=2]

\draw [fill=black](0,0) rectangle (4.5,1);
\node at (0.75,0.5) {\contour{white}{\Large Text!}};
\node [fill=white,inner sep=1pt] at (2.25,0.5) {\Large Text!};
\node [fill=white,rounded corners=2pt,inner sep=1pt] at (3.75,0.5) {\Large Text!};

\end{tikzpicture}

\end{document}

在此处输入图片描述

三:这可能有用

\documentclass{standalone}

\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[scale=2]
\node at (5,5) (p) {B}; 
\draw (p.south) -| ++(2mm,3mm) -| (p.north);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容