4

Consider the following code:

% DOCUMENT TYPE
\documentclass[12pt,a4paper]{article}

% PACKAGES
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{color}
\usepackage{tikz}
\usepackage[normalem]{ulem}
\usepackage[top=1.25in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}
\usepackage{calc}
\usetikzlibrary{calc}
\usetikzlibrary{fadings}

% DOCUMENT BEGINNING
\begin{document}
\section{First section}
\lipsum
\centerline{%
\begin{tikzpicture} 
\clip[preaction={blue,fill}] (0,0) rectangle (\paperwidth,-2cm); 
\fill[white,path fading=circle with fuzzy edge 10 percent] ( -0.92cm, -5cm) ellipse (8.9cm and 6.7cm); 
\end{tikzpicture}
}
\lipsum
\end{document}

Which produces the following: figure

Here are the two problems:

  • How to align correctly the rectangle with the page (there is a small space at the right and I don't understand why)
  • How to obtain a 5% fuzzy edge? (because currently if I write "circle with fuzzy edge 5 percent", the tex does not compile)
6

Unwanted space at the right side

The first issue is just a unwanted space by a line end:

\centerline{%
  \begin{tikzpicture}...\end{tikzpicture}
}

Then the tikzpicture with width \paperwidth plus the space after \end{tikzpicture} is centered, leaving the half of the space at the right side of the paper. Solution:

\centerline{%
  \begin{tikzpicture}...\end{tikzpicture}%
}

circle with fuzzy edge 5 percent

The number is not a variable, there are only fixed percentages:

  • circle with fuzzy edge 10 percent
  • circle with fuzzy edge 15 percent
  • circle with fuzzy edge 20 percent

They are defined in file pgflibraryfadings.code.tex. Analogous also the missing 5 percent can be defined:

\pgfdeclareradialshading{tikz@lib@fade@circle@5}{\pgfpointorigin}{%
  color(0pt)=(pgftransparent!0); color(23.75bp)=(pgftransparent!0);%
  color(25bp)=(pgftransparent!100); color(50bp)=(pgftransparent!100)%
}
\pgfdeclarefading{circle with fuzzy edge 5 percent}{%
  \pgfuseshading{tikz@lib@fade@circle@5}%
}

The only value, which needs to be recalculated for 5 percent is 23.75bp. Its 5 percent smaller than the following 25bp.

Full example:

\documentclass[12pt,a4paper]{article}

\usepackage{lipsum}
\usepackage[top=1.25in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}
\usepackage{tikz}
\usetikzlibrary{fadings}

\makeatletter
\pgfdeclareradialshading{tikz@lib@fade@circle@5}{\pgfpointorigin}{%
  color(0pt)=(pgftransparent!0); color(23.75bp)=(pgftransparent!0);%
  color(25bp)=(pgftransparent!100); color(50bp)=(pgftransparent!100)%
}
\pgfdeclarefading{circle with fuzzy edge 5 percent}{%
  \pgfuseshading{tikz@lib@fade@circle@5}%
}
\makeatother

\begin{document}
\lipsum[7]
\centerline{%
  \begin{tikzpicture}
    \clip[preaction={blue,fill}] (0,0) rectangle (\paperwidth,-2cm);
    \fill[white,path fading=circle with fuzzy edge 5 percent] ( -0.92cm, -5cm)
    ellipse (8.9cm and 6.7cm);
  \end{tikzpicture}%
}
\lipsum[1]
\end{document}

Result

  • Still I'd prefer not to see \centerline. – egreg May 17 '15 at 20:42
  • @egreg The specification about the vertical spacing before and after is missing. Therefore it must remain unclear, whether \centerline is a bad choice or even pretty clever. – Heiko Oberdiek May 17 '15 at 21:26
  • When the method is applied to an asymmetric page layout, the choice of \centerline will reveal quite unpractical. Better \par\noindent\makebox[\textwidth][l]{\hspace{-\dimexpr\oddsidemargin+1in}<picture>} with \evensidemargin for even pages (and the ifoddpage package can decide which of the two). – egreg May 17 '15 at 21:33
  • @egreg If the centered element just a colored rule across the page, then \centerline + a line with 2\paperwidth should cover the page. Otherwise the question does not clarify, where the faded area should start, relative to the page or relative to the text. It matters in list environments with additional indentations, for example. – Heiko Oberdiek May 17 '15 at 21:48
  • In the case of a list environment one just adds \@totalleftmargin. – egreg May 17 '15 at 22:02

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.