我正在试用这个新ocgx
包。它使用TikZ
节点来放置文本。不幸的是,它parindent
在节点中不起作用。有办法让它工作吗?
编辑(源代码)
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,shadows,ocgx}
\AtBeginDocument{\edef\normalparindent{\the\parindent}}
\begin{document}
\tikzset{
checkbox/.style={
draw,circle,line width=.5pt,%
minimum size=.7em,top color=white,bottom color=cyan,
fill opacity=1,
inner sep=0,
drop shadow={fill=black,shadow xshift=.5mm,shadow yshift=-.5mm},
},
mytext/.style={
text width=\textwidth,align=justify,
every node={\setlength\parindent{\normalparindent}},
inner xsep=0pt,
},
mycomment/.style={
text width=\textwidth-2cm,align=justify,
fill=yellow!20,
inner xsep=.5cm,
inner ysep=.5cm,
outer xsep=.5cm,
draw=gray,
}
}
\lipsum[1]
\bigskip
\noindent%
\begin{tikzpicture}
\begin{scope}[ocg={name=mytext,ref=mytext}]
\node[mytext]{\setlength\parindent{\normalparindent}%
In elementary algebra, the \textbf{binomial theorem} describes the algebraic expansion of powers of a binomial. According to the theorem, it is possible to expand the power $(x + y)^n$ into a sum involving terms of the form $ax^{b}y^{c}$, where the exponents $b$ and $c$ are nonnegative integers with $b + c = n$, and the coefficient $a$ of each term is a specific positive integer depending on $n$ and $b$. When an exponent is zero, the corresponding power is usually omitted from the term.
This formula and the triangular arrangement of the binomial coefficients are often attributed to Blaise Pascal, who described them in the 17th century, but they were known to many mathematicians who preceded him. The 4th century B.C. Greek mathematician Euclid mentioned the special case of the binomial theorem for exponent 2 as did the 3rd century B.C. Indian mathematician Pingala to higher orders. A more general binomial theorem and the so-called "Pascal's triangle" were known in the 10th-century A.D. to Indian mathematician Halayudha and Persian mathematician Al-Karaji, in the 11th century to Persian poet and mathematician Omar Khayyam, and in the 13th century to Chinese mathematician Yang Hui, who all derived similar results. Al-Karaji also provided a mathematical proof of both the binomial theorem and Pascal's triangle, using mathematical induction.\par
};%
\end{scope}
\begin{scope}[ocg={name=mycomment,status=invisible,ref=mycomment}]
\node[mycomment]{binomial theorem:
\begin{align}
(a+b)^{2} & = a^{2}+2ab+b^{2}\\
(a-b)^{2} & = a^{2}-2ab+b^{2}\\
(a+b)(a-b) & = a^{2}-b^{2}
\end{align}
};%
\end{scope}
\end{tikzpicture}
\par
\begin{center}
\begin{tikzpicture}
\node[checkbox,switch ocg with mark on={mycomment}{mytext,mycomment}]{};
\end{tikzpicture} show formulas
\end{center}
\bigskip
\lipsum[2]
\end{document}
- 第 1 层
- 第 2 层
- 第 2 层(编辑后新增)
答案1
我似乎没有可以处理图层的 PDF 查看器,所以我不知道这是否真的有效,但我确实知道一些如何将内容放入节点文本,所以希望以下内容是一个积极的贡献。
在某个地方,\parindent
正在重置。因此,在进入节点之前,我们需要保存当前值。为此,我们需要使用.code
处理程序。目前,在您的代码中,您有every node={\setlength\parindent{\normalparindent}}
。这实际上不会做任何事情,因为every node
它应该是一个风格它在每个节点上执行,并且你想使用它来执行一些代码(请注意,因为它是mytext
在节点的参数中调用的,使用它来设置every node
没有效果,因为它被调用后 every node
处理此节点的缩进)。因此,我们定义一个新键,它执行一些代码来保存当前的\parindent
。现在我们必须在适当的位置将其重新插入流中。为此,我们使用样式execute at begin node
。这是在节点启动其内部小页面(假设它将使用一个)之后执行的,这就是您想要恢复缩进的地方。最后,您希望\indent
缩进第一段。
这一切都是通过对代码进行以下修改来实现的:
靠近顶部:
\newlength\saveparindent
在你的风格中:
mytext/.style={
text width=\textwidth,align=justify,
save parindent,
execute at begin node={\setlength{\parindent}{\saveparindent}\indent},
inner xsep=0pt,
},
save parindent/.code={
\setlength{\saveparindent}{\parindent}%
},
最后,您不需要\setlength...
实际的节点文本。
答案2
编辑:有了你编辑的问题,这更加简单。你可以使用普通段落并且只是一个OCG(附公式)。
由于使用picture remember
将公式覆盖在文本上方,因此需要进行两次编译。mark
坐标用于标记公式的未来位置。
以下是代码:
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,shadows,ocgx}
\begin{document}
\tikzset{
checkbox/.style={
draw,circle,line width=.5pt,%
minimum size=.7em,top color=white,bottom color=cyan,
fill opacity=1,
inner sep=0,
drop shadow={fill=black,shadow xshift=.5mm,shadow yshift=-.5mm},
},
mytext/.style={
text width=\textwidth,align=justify,
inner xsep=0pt,
},
mycomment/.style={
text width=\textwidth-2cm,align=justify,
fill=yellow!20,
inner xsep=.5cm,
inner ysep=.5cm,
outer xsep=.5cm,
draw=gray,
}
}
\lipsum[1-2]
In elementary algebra, the \textbf{binomial theorem} describes the
algebraic expansion of powers of a binomial. According to the theorem,
it is possible to expand the power $(x + y)^n$ into a sum involving
terms of the form $ax^{b}y^{c}$, where the exponents $b$ and $c$ are
nonnegative integers with $b + c = n$, and the coefficient $a$ of each
term is a specific positive integer depending on $n$ and $b$. When an
exponent is zero, the corresponding power is usually omitted from the
term.\tikz[overlay,remember picture]\coordinate (mark);
This formula and the triangular arrangement of the binomial
coefficients are often attributed to Blaise Pascal, who described them
in the 17th century, but they were known to many mathematicians who
preceded him. The 4th century B.C. Greek mathematician Euclid
mentioned the special case of the binomial theorem for exponent 2 as
did the 3rd century B.C. Indian mathematician Pingala to higher
orders. A more general binomial theorem and the so-called "Pascal's
triangle" were known in the 10th-century A.D. to Indian mathematician
Halayudha and Persian mathematician Al-Karaji, in the 11th century to
Persian poet and mathematician Omar Khayyam, and in the 13th century
to Chinese mathematician Yang Hui, who all derived similar
results. Al-Karaji also provided a mathematical proof of both the
binomial theorem and Pascal's triangle, using mathematical
induction.
\begin{center}
% formulas
\begin{tikzpicture}[overlay,remember picture]
\path (mark -| current page) coordinate (origin);
\begin{scope}[ocg={name=mycomment,status=invisible,ref=mycomment}]
\node[mycomment] at (origin) {%
binomial theorem:
\begin{align}
(a+b)^{2} & = a^{2}+2ab+b^{2}\\
(a-b)^{2} & = a^{2}-2ab+b^{2}\\
(a+b)(a-b) & = a^{2}-b^{2}
\end{align}
};
\end{scope}
\end{tikzpicture}
% button
\begin{tikzpicture}
\node[checkbox,switch ocg with mark off={mycomment}{}]{};
\end{tikzpicture} show formulas
\end{center}
\bigskip
\lipsum[2]
\end{document}
第一个答案:这是您的 MWE普通段落代替TikZ 节点中的段落!
由于使用picture remember
将公式覆盖在文本上方,因此需要进行两次编译。
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,shadows,ocgx}
\begin{document}
\tikzset{
checkbox/.style={
draw,circle,line width=.5pt,%
minimum size=.7em,top color=white,bottom color=cyan,
fill opacity=1,
inner sep=0,
drop shadow={fill=black,shadow xshift=.5mm,shadow yshift=-.5mm},
},
mytext/.style={
text width=\textwidth,align=justify,
inner xsep=0pt,
},
mycomment/.style={
text width=\textwidth-2cm,align=justify,
fill=yellow!20,
inner xsep=.5cm,
inner ysep=.5cm,
outer xsep=.5cm,
draw=gray,
}
}
\lipsum[1-2]
\begin{ocg}{mytext}{mytext}{1}
In elementary algebra, the \textbf{binomial theorem} describes the
algebraic expansion of powers of a binomial. According to the theorem,
it is possible to expand the power $(x + y)^n$ into a sum involving
terms of the form $ax^{b}y^{c}$, where the exponents $b$ and $c$ are
nonnegative integers with $b + c = n$, and the coefficient $a$ of each
term is a specific positive integer depending on $n$ and $b$. When an
exponent is zero, the corresponding power is usually omitted from the
term.
\end{ocg}
\begin{tikzpicture}[overlay,remember picture]
\path (0,0 -| current page) coordinate (origin);
\begin{scope}[ocg={name=mycomment,status=invisible,ref=mycomment}]
\node[mycomment] at (origin) {binomial theorem:
\begin{align}
(a+b)^{2} & = a^{2}+2ab+b^{2}\\
(a-b)^{2} & = a^{2}-2ab+b^{2}\\
(a+b)(a-b) & = a^{2}-b^{2}
\end{align}
};%
\end{scope}
\end{tikzpicture}
\begin{ocg}{mytext}{mytext}{1}
This formula and the triangular arrangement of the binomial
coefficients are often attributed to Blaise Pascal, who described them
in the 17th century, but they were known to many mathematicians who
preceded him. The 4th century B.C. Greek mathematician Euclid
mentioned the special case of the binomial theorem for exponent 2 as
did the 3rd century B.C. Indian mathematician Pingala to higher
orders. A more general binomial theorem and the so-called "Pascal's
triangle" were known in the 10th-century A.D. to Indian mathematician
Halayudha and Persian mathematician Al-Karaji, in the 11th century to
Persian poet and mathematician Omar Khayyam, and in the 13th century
to Chinese mathematician Yang Hui, who all derived similar
results. Al-Karaji also provided a mathematical proof of both the
binomial theorem and Pascal's triangle, using mathematical
induction.
\end{ocg}
\begin{center}
\begin{tikzpicture}
\node[checkbox,switch ocg with mark on={mytext}{mycomment}]{};
\end{tikzpicture} show formulas
\end{center}
\bigskip
\lipsum[2]
\end{document}
答案3
显然,它已被某人重置(一些代码片段?我不知道)。手动激活它可以起作用:
\node[mytext]{
\parindent=50pt
In elementary algebra, the ....