当导入svg
到使用的投影仪演示文稿中时\pgfsetfillopacity
,半透明度将停止工作。
例如,下面的代码在加载和不加载包的情况下会产生不同的结果
不含svg
包装:
附带svg
包装:
有没有办法修补svg
或变通办法将其与投影仪半透明功能一起使用?(或者问题可能与之有关pgf
?)
% code from http://tex.stackexchange.com/a/44716/7561
\documentclass[compress]{beamer}
\usecolortheme{rose}
% switch this on or off
%\usepackage{svg}
\usebackgroundtemplate{\centering
\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}
\addtobeamertemplate{block begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block alerted begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block example begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\begin{document}
\begin{frame}{}
\begin{theorem}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue.
\end{theorem}
\begin{alertblock}{Alert!!!}
Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\end{alertblock}
\begin{exampleblock}{Example}
Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.
\end{exampleblock}
\end{frame}
\end{document}
扩展示例,包含一个.svg
文件。
% code from http://tex.stackexchange.com/a/44716/7561
\documentclass[compress]{beamer}
\usepackage{filecontents}
\begin{filecontents*}{sample.svg}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="19.581747mm"
height="37.898418mm"
viewBox="0 0 69.384143 134.28573"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="example.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="-280.71427"
inkscape:cy="48.571435"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1331"
inkscape:window-height="750"
inkscape:window-x="29"
inkscape:window-y="18"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-254.2857,-446.64791)">
<path
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 271.42857,580.93363 c 62.85714,-37.14285 51.42857,-85.71428 51.42857,-85.71428 l -68.57143,-48.57143 31.42858,71.42857 z"
id="path4136"
inkscape:connector-curvature="0" />
</g>
</svg>
\end{filecontents*}
\usecolortheme{rose}
% this definition creates an error on the last frame
\makeatletter
\@namedef{transparent}%
\makeatother
% switch this on or off
\usepackage{svg}
\usebackgroundtemplate{\centering
\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}
\addtobeamertemplate{block begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block alerted begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block example begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\begin{document}
\begin{frame}{}
\begin{theorem}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue.
\end{theorem}
\begin{alertblock}{Alert!!!}
Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\end{alertblock}
\begin{exampleblock}{Example}
Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.
\end{exampleblock}
\end{frame}
% this produces an error when \@namedef is used
\begin{frame}
\includesvg{sample}
\end{frame}
\end{document}
答案1
新解决方案基于https://tex.stackexchange.com/a/390317/36296
% code from http://tex.stackexchange.com/a/44716/7561
\documentclass[compress]{beamer}
\usecolortheme{rose}
% from https://tex.stackexchange.com/a/390317/36296
\expandafter\def\csname [email protected]\endcsname{}
% switch this on or off
\usepackage{svg}
\usebackgroundtemplate{\centering
\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}
\addtobeamertemplate{block begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block alerted begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block example begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\begin{document}
\begin{frame}{}
\begin{theorem}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue.
\end{theorem}
\begin{alertblock}{Alert!!!}
Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\end{alertblock}
\begin{exampleblock}{Example}
Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.
\end{exampleblock}
\end{frame}
\end{document}
将有问题的包替换svg
为https://www.ctan.org/pkg/svg-inkscape工作 - 这需要inkscape
安装,但看看你的示例 svg 的创建者,这应该不是问题。
% !TeX program = txs:///arara
% arara: pdflatex: {shell: true}
\documentclass[compress]{beamer}
\usepackage{filecontents}
\begin{filecontents*}{sample.svg}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="19.581747mm"
height="37.898418mm"
viewBox="0 0 69.384143 134.28573"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="example.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="-280.71427"
inkscape:cy="48.571435"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1331"
inkscape:window-height="750"
inkscape:window-x="29"
inkscape:window-y="18"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-254.2857,-446.64791)">
<path
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 271.42857,580.93363 c 62.85714,-37.14285 51.42857,-85.71428 51.42857,-85.71428 l -68.57143,-48.57143 31.42858,71.42857 z"
id="path4136"
inkscape:connector-curvature="0" />
</g>
</svg>
\end{filecontents*}
\usecolortheme{rose}
\newcommand{\executeiffilenewer}[3]{%
\ifnum\pdfstrcmp{\pdffilemoddate{#1}}%
{\pdffilemoddate{#2}}>0%
{\immediate\write18{#3}}\fi%
}
\newcommand{\includesvg}[1]{%
\executeiffilenewer{#1.svg}{#1.pdf}%
{inkscape -z -D --file=#1.svg %
--export-pdf=#1.pdf --export-latex}%
\input{#1.pdf_tex}%
}
\usebackgroundtemplate{\centering
\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}
\addtobeamertemplate{block begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block alerted begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block example begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\begin{document}
\begin{frame}{}
\begin{theorem}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue.
\end{theorem}
\begin{alertblock}{Alert!!!}
Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\end{alertblock}
\begin{exampleblock}{Example}
Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.
\end{exampleblock}
\end{frame}
% this produces an error when \@namedef is used
\begin{frame}
\includesvg{sample}
\end{frame}
\end{document}