垂直线和文字

垂直线和文字

我正在尝试在边距中插入一条垂直线和一些文本或图像,就像图片中那样,无论它是图像还是包含多行的文本在此处输入图片描述

但是源代码将行和文本嵌入所有页面,并且 \begin{document} 之后的文本太窄。

感谢您的支持

\documentclass[10pt,a4paper]{article}
\usepackage[all]{background}
\usepackage{lipsum}

\SetBgContents{Text here but with several lines}% Set contents
\SetBgPosition{-0.0cm,1.5cm}% Select location
\SetBgOpacity{1.0}% Select opacity
\SetBgAngle{0.0}% Select rotation of logo
\SetBgScale{1.0}% Select scale factor of logo

\newlength{\leftrule}
\newlength{\rightrule}
\setlength{\leftrule}{2\leftmargin-\marginparsep}
\setlength{\rightrule}{2\leftmargin+\textwidth+\marginparsep}
 \AddToShipoutPicture{%
\AtPageLowerLeft{%
\put(\LenToUnit{\leftrule},0){\rule{0.3pt}{\paperheight}}  % Rule on the left
%\put(\LenToUnit{\rightrule},0){\rule{1pt}{\paperheight}}  % Rule on the right
}
}

\begin{document}
\lipsum
\end{document}

答案1

我会用这个fancyhdr包来实现这一点。参见示例。它肯定包含许多硬编码常量,因此可以做得更好。

\documentclass[10pt,a4paper,draft]{article}
\usepackage[all]{background}
\usepackage{lipsum}
\usepackage{tikz}

\def\pictureOne{\begin{tikzpicture}\draw[red] (0,0)--(0,2)--(2,2)--(2,0)--cycle;\end{tikzpicture}}
\def\pictureTwo{\begin{tikzpicture}\draw[blue] (0,0)--(0,2)--(2,2)--(2,0)--cycle;\end{tikzpicture}}

\usepackage{fancyhdr}
\pagestyle{fancy}

\def\headrulewidth{0pt}
\newlength{\ruleheight}
\setlength{\ruleheight}{\textheight}
\addtolength{\ruleheight}{20mm}
\fancyhead{}
\fancyhead[L]{%
    \vbox to 0pt{%
    \vskip 5mm \hbox{%
        \hskip-5mm\vrule height\ruleheight%
        \hskip-25mm\vbox to \ruleheight{\pictureOne\vss\pictureTwo}}%
        \vss}}
\fancyfoot{}
\fancyfoot[C]{\footnotesize\thepage}

\begin{document}
\lipsum
\end{document}

答案2

您的代码已使用eso-pic规则的命令。您可以将其用于规则和文本。使用星号形式,\AddToShipoutPicture*内容将仅添加到下一个/当前页面,然后发送出去。

该包消除了在图片命令的位置参数中picture使用长度/尺寸的需要,例如。我还使用 e-TeX 原语来计算一些尺寸。\LenToUnit\put\dimexpr

\documentclass[10pt,a4paper]{article}
\usepackage{lipsum}

\usepackage{eso-pic,picture}
\AddToShipoutPicture*{% star form for add to next shipout only
  \AtPageLowerLeft{%
    \put(\dimexpr
    \oddsidemargin+1in-\marginparsep\relax,0){\rule{0.3pt}{\paperheight}}%
  }%
  \AtPageUpperLeft{%
    \put(\marginparsep,-\baselineskip){%
      \parbox[t]{\dimexpr \oddsidemargin+1in-3\marginparsep}{%
        Text here but with several lines}%
    }%
  }%
}

\begin{document}
\lipsum
\end{document}

允许\parbox使用多行文本。如果您只想要一张图片,您可以使用\makebox将其置于边距中央:

\documentclass[10pt,a4paper]{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{eso-pic,picture}
\AddToShipoutPicture*{% star form for add to next shipout only
  \AtPageLowerLeft{%
    \put(\dimexpr
    \oddsidemargin+1in-\marginparsep\relax,0){\rule{0.3pt}{\paperheight}}%
  }%
  \AtPageUpperLeft{%
    \put(\marginparsep,-\baselineskip){%
      \parbox[t]{\dimexpr \oddsidemargin+1in-3\marginparsep}{%
        Text here but with several lines}%
    }%
  }%
  \AtPageLowerLeft{%
    \put(\marginparsep,-\baselineskip){%
      \makebox(\dimexpr \oddsidemargin+1in-3\marginparsep,5cm)[c]{%
        \includegraphics[width=2cm,height=3cm]{example-image}%
      }
    }
  }
}

\begin{document}
\lipsum
\end{document}

一页带边距内容

相关内容