2

I found a template for a title page: https://www.latextemplates.com/template/vertical-line-title-page

There's a piece of code that draws a vertical line:

\rule{1pt}{\textheight} % Vertical line

I've worked out that I can add color in the following way:

\textcolor{mycolor}{\rule{3pt}{\textheight}}

However, this makes the line only single color. The title of my book is "The Rainbow Book", so I'd like the line to be... well - a rainbow. Is there a simple way e.g. to define my color as a gradient or so ?

6

No gradient really yet, just a bunch of vertical lines with colors changing from red to violet in \foreach loop.

\documentclass{article}
\usepackage[named]{xcolor}
\usepackage{pgffor}
\begin{document}
\foreach \x in {red,orange,yellow,green,blue,violet} {%
\textcolor{\x}{\rule{3pt}{\textheight}}%
}
\end{document}

And another version with TikZ and a vertical shading with \pgfdeclareverticalshading, which is taken from the pgf manual (see page 1088 of current manual version). It starts from red to blue but the shading is different, so shading angle=270 is used in order to rotate the order of the direction, otherwise use shading angle=90. If a vertical shading is desired, omit the shading angle key.

\documentclass{article}
\usepackage[named]{xcolor}
\usepackage{pgffor}
\usepackage{tikz}
\usetikzlibrary{shadings}

\pgfdeclareverticalshading{rainbow}{100bp}
{color(0bp)=(red); color(25bp)=(red); color(35bp)=(yellow);
color(45bp)=(green); color(55bp)=(cyan); color(65bp)=(blue);
color(75bp)=(violet); color(100bp)=(violet)}
\begin{document}
\begin{tikzpicture}
\shade[shading=rainbow,shading angle=270] (0,0) rectangle (5cm,\textheight);
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    ...what about indigo (I guess ...,blue,blue!50!violet,violet would work)? – Werner Jul 10 '17 at 23:58
  • @Werner: That works, but in this case the width of the rule is too large, in my opinion. The TikZ version is cleaner, I think. There are of course other solutions as well, with pstricks etc. – user31729 Jul 11 '17 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.