2

Can you please let me know how to draw a horizontal line with variable transparency similar to the figure attached below. Thank you!

enter image description here

There is a similar question answered by @Emma and @Sigur, which addresses horizontal rule with a color gradient. But, I couldn't figure out how to make the horizontal rule fade at both ends.

| improve this question | | | | |
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Tiuri Dec 4 '19 at 10:27
3

A quick adaption of this answer to the linked question yields:

\documentclass{article}
\usepackage{lipsum}%dummy text only
\usepackage{tikz}
\usetikzlibrary{fadings}
\newcommand{\gradient}{\noindent%
    \begin{tikzpicture}
    \fill[black,path fading=west] (-0.5\linewidth,0) rectangle (0,1ex);
    \fill[black,path fading=east] (0,0) rectangle (0.5\linewidth,1ex);
    \end{tikzpicture}%
}
\begin{document}
\lipsum[1]
\gradient{}
\lipsum[2]
\end{document}

enter image description here

| improve this answer | | | | |
2

Here is another version that controls the appearance of the rule with various pgf keys and draws the thing in one stretch.

\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{fadings}
\tikzfading[name=fade out,
left color=transparent!100,right color=transparent!100,
middle color=transparent!0]
\tikzset{faded rule style/.style={},faded rule/.cd,color/.initial=black,width/.initial=\textwidth,
height/.initial=1ex,style/.code=\tikzset{faded rule style/.style={#1}}}

\newcommand{\FadeRule}[1][]{\noindent\tikz{\def\pv##1{\pgfkeysvalueof{/tikz/faded rule/##1}}
\tikzset{faded rule/.cd,#1}
\path(-\textwidth/2,0) -- (\textwidth/2,0);
\fill[faded rule style,color=\pv{color},path fading=fade out] (-\pv{width}/2,-\pv{height}/2)
rectangle (\pv{width}/2,\pv{height}/2);}}

\begin{document}
\lipsum[1]

\FadeRule

\lipsum[2]

\FadeRule[color=blue,height=1em]

\lipsum[3]

\FadeRule[color=red,width=0.7\textwidth]

\lipsum[3]

\FadeRule[style={opacity=0.5}]
\end{document}

enter image description here

| improve this answer | | | | |

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.