开发者

Semi-transparent text in beamer (pdflatex)

I want to have some text appear semi-transparent, but not in an overlay fashion (where it eventually becomes solid) just permanently semi-tra开发者_运维问答nsparent. To complicate matters, the text in question is part of a matrix:

$
\begin{matrix}
          & \{-2,3,5,0,8\} & \\
    \{-2,3,5,0\} & & \{-2,3,5,8\} \\
          & \{-2,3,5\} &
\end{matrix}
$

I want the third line in the matrix to be semi-transparent. Is there a way to do this?


Edit: improved the solution by turning it into a command with an optional argument.

Okay, discovered how to do it:

\newcommand{\semitransp}[2][35]{\textcolor{fg!#1}{#2}}

...

$
\begin{matrix}
       & \{-2,3,5,0,8\} & \\
    \{-2,3,5,0\} & & \{-2,3,5,8\} \\
      & \semitransp{\{-2,3,5\}} &
\end{matrix}
$

The optional parameter controls the transparency. So \semitransp[20]{text} is lighter, and \semitransp[60]{text} is heavier. The default value 35 looks good on my computer screen. It is yet to be seen how it looks projected on a wall.


Ari's answer may work for him (and in 2010), but the given command will make all following text transparent, not only the given text.

An improved solution for making only the given text transparent:

\newcommand{\semitransp}[2][35]{\textcolor{fg!#1}{#2}}
% Swap \color with \textcolor and add another curly brackets pair.

...

$
\begin{matrix}
   & \{-2,3,5,0,8\} & \\
\{-2,3,5,0\} & & \{-2,3,5,8\} \\
  & \semitransp{\{-2,3,5\}} &
\end{matrix}
$


To get real semi-transparency, one can use \pgfsetfillopacity. The advantage compared to faking the opacity by mixing the foreground colour with the background is, that this will also work if the there is a background image or some other coloured element.

\documentclass{beamer}

\begin{document}

\begin{frame}
$
\begin{matrix}
          & \{-2,3,5,0,8\} & \\
    \{-2,3,5,0\} & & \{-2,3,5,8\} \\
          & {\pgfsetfillopacity{0.2}\{-2,3,5\}} &
\end{matrix}
$

\end{frame} 


\setbeamertemplate{background canvas}{\includegraphics[width=\paperwidth]{example-grid-100x100bp}}


\begin{frame}
$
\begin{matrix}
          & \{-2,3,5,0,8\} & \\
    \{-2,3,5,0\} & & \{-2,3,5,8\} \\
          & {\pgfsetfillopacity{0.2}\{-2,3,5\}} &
\end{matrix}
$

\end{frame}     

\end{document}


I came across the same problem but the approach suggested above did not work if an environment redefines the font or color. A more robust approach seems to use the package transparent from https://ctan.org/pkg/transparent

    \usepackage{transparent}
    \newcommand{\semitransp}[2][0.35]{{\transparent{#1}#2}}

A full working example is:

\documentclass{beamer}
\usepackage{transparent}
\newcommand{\semitransp}[2][0.35]{{\transparent{#1}#2}}


\begin{document}
    
\begin{frame}
  \semitransp{
    This is transparent. 
    \begin{itemize}
      \item This is also transparent.
    \end{itemize}
  }
\end{frame}

\end{document}

(this example works with the transparentpackage but not with the textcolor approach.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜