# Vertical line and text

I am trying to insert a vertical line and some text or image in the margin as in the picture no matter if it is an image or a text with several lines

However the source code embeds the line and text in all pages and the text after the \begin{document} is too narrow.

Thanks for the support

\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}
\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}

• Your code example is not compilable. It throws several errors. – Schweinebacke Feb 5 '17 at 18:09

I'd use the fancyhdr package for that. See the example. It surely contains many hardcoded constants, so it could be done better.

\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}

\newlength{\ruleheight}
\setlength{\ruleheight}{\textheight}
\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}


You're code already uses commands of eso-pic for the rule. You can use it for the rule and text. With the star form \AddToShipoutPicture* the contents will be added only to the next/current page, that will be shipped out.

Package picture eliminates the need of using \LenToUnit for length/dimensions in the position arguments of picture commands like \put. I also use e-TeX primitive \dimexpr to calculate some dimensions.

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

\usepackage{eso-pic,picture}
\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}


The \parbox allows to use several lines of text. If you want an image only, you can use \makebox to center it in the margin:

\documentclass[10pt,a4paper]{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{eso-pic,picture}
\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}