Text FormattingCustom/Macro Opacity

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Custom/Macro Opacity

Post by LaTexLearner »

Is there any way to set a custom opacity?

My laser printer just printed some documents I created and I realized that the opacity was too low. Now I have to go back and change a whole lot of opacity settings. If only I'd had a custom macro/setting for that... Is that possible?

Something like \newopacity{\answeropacity}{0.8}?

Code: Select all

\documentclass{article}

% This didn't work...
%\newopacity{\answeropacity}{0.8}

\usepackage{tikz}

\begin{document}

\begin{enumerate} 
\item Draw a length that represents two starting from zero.

\tikz
{
 \draw (0,0)--(4,0); 
 \foreach \x in {0,...,4}
  {
   \draw (\x,-0.2)--(\x,0.2);
   \node[below] at (\x,-0.3) {\x};
  }
 \fill[opacity=0.5] (0,0) rectangle (2,0.2);
}

\item Draw a length that represents four starting from zero.

\tikz
{
 \draw (0,0)--(5,0); 
 \foreach \x in {0,...,5}
  {
   \draw (\x,-0.2)--(\x,0.2);
   \node[below] at (\x,-0.3) {\x};
  }
 \fill[opacity=0.5] (0,0) rectangle (4,0.2);
}

\end{enumerate}

\end{document}
Last edited by LaTexLearner on Mon Sep 21, 2015 2:58 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Custom/Macro Opacity

Post by cgnieder »

Use

Code: Select all

\newcommand{\answeropacity}{0.8}
and then in your TikZ

Code: Select all

\fill[opacity=\answeropacity]
site moderator & package author
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Re: Custom/Macro Opacity

Post by LaTexLearner »

Awesome. I look forward to trying that tonight.
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Re: Custom/Macro Opacity

Post by LaTexLearner »

Worked perfectly, thanks! :)
Post Reply