How to add a particular object to an `ocg` list The Next CEO of Stack OverflowChecking whether...
How to show a landlord what we have in savings?
How to pronounce fünf in 45
Car headlights in a world without electricity
Salesforce opportunity stages
Ising model simulation
Upgrading From a 9 Speed Sora Derailleur?
Which acid/base does a strong base/acid react when added to a buffer solution?
What steps are necessary to read a Modern SSD in Medieval Europe?
Can you teleport closer to a creature you are Frightened of?
Is it reasonable to ask other researchers to send me their previous grant applications?
Is it possible to create a QR code using text?
"Eavesdropping" vs "Listen in on"
Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?
Create custom note boxes
Is a linearly independent set whose span is dense a Schauder basis?
How to implement Comparable so it is consistent with identity-equality
Horror film about a man brought out of cryogenic suspension without a soul, around 1990
Could a dragon use its wings to swim?
How can I prove that a state of equilibrium is unstable?
Is it possible to make a 9x9 table fit within the default margins?
Calculating discount not working
Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?
Free fall ellipse or parabola?
How can I separate the number from the unit in argument?
How to add a particular object to an `ocg` list
The Next CEO of Stack OverflowChecking whether or not a node has been previously definedHow to draw a diagram of custom subject correlativitiesDesign an algorithm capable of predicting collisions to choose alternative path using `tikzpicture` environmentHow to connect `pic`s through a set of colorful arrows using `tikzpicture` environmentHow to put a box and use columns to separate arrowsAlignment of TikZ objectHow to add label to a 'copy shadow' of an object?Bend 3D cylindrical objectTikZ/ERD: node (=Entity) label on the insidedebugging tikz: how assign each separate tikz object to a variable and then add them to a picture?Redefine object inside a loopDrawing solid object by TikzMultiple choice questions linked to solutions using Optional Content Groups (OCG)How to draw “particular” arrow in TikzIs there a bug with the `switch ocg with mark on` key of the ocgx and ocgx2 packages?
This is an addendum of a previous question: How to put a box and use columns to separate arrows.
Please consider this MWE (adapted from a nice answer of that question):
documentclass{article}
usepackage[margin=0in,footskip=0in]{geometry}
usepackage[english]{babel}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{hyperref}
usepackage[tikz]{ocgx2}
usepackage{amssymb} % checkmark
% check box command for layer switching
newcommandlayerCheckBox[3]{%
% #1: switch id, if empty use #2 instead
% #2: layer ids to be toggled (space separated if multiple ids),
% #3: initial visibility
resizebox{2ex}{!}{%
ooalign{%
switchocg{#1 #2}{$square$}cr%
begin{ocg}{%
ifxnil#1nil#2else#1fi%
}%
{%
ifxnil#1nil#2else#1fi%
}{#3}$checkmark$%
end{ocg}%
}%
}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
usepackage{tikz}
usetikzlibrary{positioning,fit,calc}
pgfdeclarelayer{behind}
pgfdeclarelayer{background}
pgfdeclarelayer{foreground}
pgfsetlayers{behind,background,main,foreground}
tikzset{
text field/.style={text height=1.5ex,align=center,rounded corners},
nonfillable title field/.style={text height=2ex,text depth=0.3em,anchor=south,text
width=5cm,align=center,font=footnotesizesffamily},
pics/nonfillable subject/.style={code={%
node[text field] (-TF)
{hspace{1.2em}~/~hspace{1.15em}~/~hspace{2.35em}{}};
node[nonfillable title field] (-Title)
at ([yshift=0.4em]-TF.north) {#1};
draw[rounded corners] (-TF.south west) |- (-Title.south west)
|- (-Title.north east) -- (-Title.south east) -| (-TF.south east)
-- cycle;
draw ([xshift=4pt]-Title.south west) -- ([xshift=-4pt]-Title.south east);
}},
manoooh/.style={column sep=-1.75cm,row sep=5mm},
fit sep/.initial=4pt, % change width of node (big rectangle shape)
fit dist/.initial=40pt, % change node distance (big rectangle shape)
inlay top sep/.initial=24pt,
matrix top sep/.initial=24pt,
manoooh curve/.style={to path={let p1=($(tikztotarget)-(tikztostart)$)
in (tikztostart) .. controls ($(tikztostart)+(#1*x1,0)$)
and ($(tikztotarget)+(-#1*x1,0)$) .. (tikztotarget)}},
manoooh curve/.default=0.3,
along node/.style={insert path={
to[out=0,in=180]
([yshift=5pt]#1-Title.north west) -- ([yshift=5pt]#1-Title.north east)}}
} % From https://tex.stackexchange.com/a/478723/152550
makeatletter% from https://tex.stackexchange.com/a/85531/121799
longdefifnodedefined#1#2#3{%
@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%
newcommandtotalnodes{1} % Define the total of subjects that need arrows-1
%%%%%%%%%%%%%%%%%%%%%%%%%
begin{document}
ifdefinedmymatbottom
else
typeout{Pleasespace recompilespace yourspace file!}
defmymatbottom{-150pt}
fi
ifdefinedmyheight
else
defmyheight{0}
typeout{Pleasespace recompilespace yourspace file!}
fi
ifdefinedLstMatYShifts
else
defLstMatYShifts{{0pt,0pt,0pt,0pt,0pt,0pt,0pt}}
fi
ifdefinedLstMatXShifts
else
defLstMatXShifts{{0pt,0pt,0pt,0pt,0pt,0pt,0pt}}
fi
begin{tikzpicture}
% step 1: add the matrices, name them mat0, mat1 etc.
begin{scope}[local bounding box=matrices]
matrix[manoooh] (mat0) at ({LstMatXShifts[0]},{LstMatYShifts[0]}) {
pic[local bounding box=A] (0) {nonfillable subject={Subject0}}; & &
pic (1) {nonfillable subject={Subject1}}; \
& pic (2) {nonfillable subject={Subject2}}; & \
};
matrix[manoooh] (mat1) at ({LstMatXShifts[1]},{LstMatYShifts[1]}) {
pic (3) {nonfillable subject={Subject3}}; \
pic (4) {nonfillable subject={Subject4}}; \
pic (5) {nonfillable subject={Subject5}}; \
pic (6) {nonfillable subject={Subject6}}; \
pic (7) {nonfillable subject={Subject7}}; \
pic (8) {nonfillable subject={Subject8}}; \
};
end{scope}
pgfmathsetmacro{groupwidth}{0}
pgfmathsetmacro{lastwidth}{0}
foreach X in {0,...,1}{ %<- if you have more or less matrices, adjust 3
ifnodedefined{matEX}
{
% has inlay
}
{
% no inlay
path
let p1=($(matX.north east)-(matX.south west)$),
n1={max(abs(y1)/2,mymatbottom)}
in
pgfextra{xdefmymatbottom{n1}
ifnumX=0
pgfmathsetmacro{groupwidth}{0}
else
pgfmathsetmacro{groupwidth}{groupwidth+x1/2+lastwidth/2+pgfkeysvalueof{/tikz/fit dist}}
fi
xdefgroupwidth{groupwidth}
xdeflastwidth{x1}
pgfmathsetmacro{myheight}{max(y1+pgfkeysvalueof{/tikz/matrix top sep},myheight)}
xdefmyheight{myheight}
ifnumX=0
xdefLstMatYShifts{0pt}
xdefLstMatXShifts{0pt}
else
xdefLstMatYShifts{LstMatYShifts,0pt}
xdefLstMatXShifts{LstMatXShifts,groupwidth pt}
fi};
% the fit parameters determine the shape of the background rectangles
}
}
makeatletter
immediatewrite@mainaux{xdefstringmymatbottom{-mymatbottom}relax}
immediatewrite@mainaux{xdefstringmyheight{myheight}relax}
immediatewrite@mainaux{xdefstringLstMatYShifts{{LstMatYShifts}}relax}
immediatewrite@mainaux{xdefstringLstMatXShifts{{LstMatXShifts}}relax}
makeatother
% From https://tex.stackexchange.com/a/480685/152550
% now add the arrows.
gdefLstCon{%
{
"{6/1}",
"{4}",
}
}
pgfmathsetmacro{mylst}{LstCon[0]}
foreach X in {0,...,totalnodes} {
begin{scope}[ocg={name={ArrowX},ref=myArrowX,status=visible}]
pgfmathsetmacro{huenum}{X*0.75*(1/totalnodes)}
definecolor{mycolor}{hsb}{huenum,1,1}
pgfmathsetmacro{mylst}{LstCon[X]}
%typeout{X:mylst}
foreach Y/myalong in mylst {
ifxmyalongY
%typeout{X:Y,empty}
draw[-latex,mycolor,very thick] (X-Title.east)
to[manoooh curve] (Y-Title.west);
else
%typeout{X:Yspace andspace myalong}
draw[-latex,mycolor,very thick] (X-Title.east)
[along node/.list/.expanded=myalong]
to[manoooh curve] (Y-Title.west);
fi
}
end{scope}
}
%pgfmathsetmacro{huenumm}{2*0.75*(1/totalnodes)}
%definecolor{mycolor2}{hsb}{huenumm,1,1}
%draw[-latex,mycolor2,very thick] (2-Title.east) -- ++ (3,0) to[manoooh curve=1.6] (3-Title.west);
end{tikzpicture}
flushleft
qquadparbox{0.4linewidth}{%
hypersetup{pdfborder={0 0 0}}%
% list of OCGs, space separated
defocglist{}%
foreach X in {0,...,totalnodes} {xdefocglist{ocglistspace myArrowX}}
fbox{%
parbox{12cm}{%
% on/off All
showocg{ocglist}{fboxsep=1ptfbox{rule{0pt}{1.7ex}on}}/%
hideocg{ocglist}{fboxsep=1ptfbox{rule{0pt}{1.7ex}off}} All\%
% checkboxes
foreach X in {0,...,totalnodes} {%
layerCheckBox{}{myArrowX}{on}begin{tikzpicture}[baseline=-1ex]%
pgfmathsetmacro{huenum}{X*0.75*(1/totalnodes)}%
definecolor{mycolor}{hsb}{huenum,1,1}draw[-latex,mycolor,very thick] (0,0) -- (1,0);%
end{tikzpicture}qquad%
}%
}
}
}
end{document}
It works fantastic.
Now I want to add another arrow, that goes from (2)
to (3)
, so one would probably add
"{3}",
to the LstCon
object (please increment the value of totalnodes
by 1!), but this produces an ugly output, because it collides with "Subject1".
To fix this, I have been told that I need to create this new arrow outside the foreach
loop that it is inside the tikzpicture
environment. So I have deleted "{3}",
and added the following three lines to the code:
pgfmathsetmacro{huenumm}{2*0.75*(1/totalnodes)}
definecolor{mycolor2}{hsb}{huenumm,1,1}
draw[-latex,mycolor2,very thick] -- ++ (3,0) (2-Title.east) to[manoooh curve=1.6] (3-Title.west);
You only need to uncomment that lines of the given MWE to get this output:
It looks like there are no problems.
However, adding that arrow outside the foreach
loop makes the checkbox of it non-clickable:
I want to make it possible to click on this new checkbox. How can we do it?
Thanks!!
P.S. Also I am getting an overfull hbox
bad box message because of the parbox
. Could you consider try to find out why I am getting it?
tikz-pgf ocgx2
add a comment |
This is an addendum of a previous question: How to put a box and use columns to separate arrows.
Please consider this MWE (adapted from a nice answer of that question):
documentclass{article}
usepackage[margin=0in,footskip=0in]{geometry}
usepackage[english]{babel}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{hyperref}
usepackage[tikz]{ocgx2}
usepackage{amssymb} % checkmark
% check box command for layer switching
newcommandlayerCheckBox[3]{%
% #1: switch id, if empty use #2 instead
% #2: layer ids to be toggled (space separated if multiple ids),
% #3: initial visibility
resizebox{2ex}{!}{%
ooalign{%
switchocg{#1 #2}{$square$}cr%
begin{ocg}{%
ifxnil#1nil#2else#1fi%
}%
{%
ifxnil#1nil#2else#1fi%
}{#3}$checkmark$%
end{ocg}%
}%
}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
usepackage{tikz}
usetikzlibrary{positioning,fit,calc}
pgfdeclarelayer{behind}
pgfdeclarelayer{background}
pgfdeclarelayer{foreground}
pgfsetlayers{behind,background,main,foreground}
tikzset{
text field/.style={text height=1.5ex,align=center,rounded corners},
nonfillable title field/.style={text height=2ex,text depth=0.3em,anchor=south,text
width=5cm,align=center,font=footnotesizesffamily},
pics/nonfillable subject/.style={code={%
node[text field] (-TF)
{hspace{1.2em}~/~hspace{1.15em}~/~hspace{2.35em}{}};
node[nonfillable title field] (-Title)
at ([yshift=0.4em]-TF.north) {#1};
draw[rounded corners] (-TF.south west) |- (-Title.south west)
|- (-Title.north east) -- (-Title.south east) -| (-TF.south east)
-- cycle;
draw ([xshift=4pt]-Title.south west) -- ([xshift=-4pt]-Title.south east);
}},
manoooh/.style={column sep=-1.75cm,row sep=5mm},
fit sep/.initial=4pt, % change width of node (big rectangle shape)
fit dist/.initial=40pt, % change node distance (big rectangle shape)
inlay top sep/.initial=24pt,
matrix top sep/.initial=24pt,
manoooh curve/.style={to path={let p1=($(tikztotarget)-(tikztostart)$)
in (tikztostart) .. controls ($(tikztostart)+(#1*x1,0)$)
and ($(tikztotarget)+(-#1*x1,0)$) .. (tikztotarget)}},
manoooh curve/.default=0.3,
along node/.style={insert path={
to[out=0,in=180]
([yshift=5pt]#1-Title.north west) -- ([yshift=5pt]#1-Title.north east)}}
} % From https://tex.stackexchange.com/a/478723/152550
makeatletter% from https://tex.stackexchange.com/a/85531/121799
longdefifnodedefined#1#2#3{%
@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%
newcommandtotalnodes{1} % Define the total of subjects that need arrows-1
%%%%%%%%%%%%%%%%%%%%%%%%%
begin{document}
ifdefinedmymatbottom
else
typeout{Pleasespace recompilespace yourspace file!}
defmymatbottom{-150pt}
fi
ifdefinedmyheight
else
defmyheight{0}
typeout{Pleasespace recompilespace yourspace file!}
fi
ifdefinedLstMatYShifts
else
defLstMatYShifts{{0pt,0pt,0pt,0pt,0pt,0pt,0pt}}
fi
ifdefinedLstMatXShifts
else
defLstMatXShifts{{0pt,0pt,0pt,0pt,0pt,0pt,0pt}}
fi
begin{tikzpicture}
% step 1: add the matrices, name them mat0, mat1 etc.
begin{scope}[local bounding box=matrices]
matrix[manoooh] (mat0) at ({LstMatXShifts[0]},{LstMatYShifts[0]}) {
pic[local bounding box=A] (0) {nonfillable subject={Subject0}}; & &
pic (1) {nonfillable subject={Subject1}}; \
& pic (2) {nonfillable subject={Subject2}}; & \
};
matrix[manoooh] (mat1) at ({LstMatXShifts[1]},{LstMatYShifts[1]}) {
pic (3) {nonfillable subject={Subject3}}; \
pic (4) {nonfillable subject={Subject4}}; \
pic (5) {nonfillable subject={Subject5}}; \
pic (6) {nonfillable subject={Subject6}}; \
pic (7) {nonfillable subject={Subject7}}; \
pic (8) {nonfillable subject={Subject8}}; \
};
end{scope}
pgfmathsetmacro{groupwidth}{0}
pgfmathsetmacro{lastwidth}{0}
foreach X in {0,...,1}{ %<- if you have more or less matrices, adjust 3
ifnodedefined{matEX}
{
% has inlay
}
{
% no inlay
path
let p1=($(matX.north east)-(matX.south west)$),
n1={max(abs(y1)/2,mymatbottom)}
in
pgfextra{xdefmymatbottom{n1}
ifnumX=0
pgfmathsetmacro{groupwidth}{0}
else
pgfmathsetmacro{groupwidth}{groupwidth+x1/2+lastwidth/2+pgfkeysvalueof{/tikz/fit dist}}
fi
xdefgroupwidth{groupwidth}
xdeflastwidth{x1}
pgfmathsetmacro{myheight}{max(y1+pgfkeysvalueof{/tikz/matrix top sep},myheight)}
xdefmyheight{myheight}
ifnumX=0
xdefLstMatYShifts{0pt}
xdefLstMatXShifts{0pt}
else
xdefLstMatYShifts{LstMatYShifts,0pt}
xdefLstMatXShifts{LstMatXShifts,groupwidth pt}
fi};
% the fit parameters determine the shape of the background rectangles
}
}
makeatletter
immediatewrite@mainaux{xdefstringmymatbottom{-mymatbottom}relax}
immediatewrite@mainaux{xdefstringmyheight{myheight}relax}
immediatewrite@mainaux{xdefstringLstMatYShifts{{LstMatYShifts}}relax}
immediatewrite@mainaux{xdefstringLstMatXShifts{{LstMatXShifts}}relax}
makeatother
% From https://tex.stackexchange.com/a/480685/152550
% now add the arrows.
gdefLstCon{%
{
"{6/1}",
"{4}",
}
}
pgfmathsetmacro{mylst}{LstCon[0]}
foreach X in {0,...,totalnodes} {
begin{scope}[ocg={name={ArrowX},ref=myArrowX,status=visible}]
pgfmathsetmacro{huenum}{X*0.75*(1/totalnodes)}
definecolor{mycolor}{hsb}{huenum,1,1}
pgfmathsetmacro{mylst}{LstCon[X]}
%typeout{X:mylst}
foreach Y/myalong in mylst {
ifxmyalongY
%typeout{X:Y,empty}
draw[-latex,mycolor,very thick] (X-Title.east)
to[manoooh curve] (Y-Title.west);
else
%typeout{X:Yspace andspace myalong}
draw[-latex,mycolor,very thick] (X-Title.east)
[along node/.list/.expanded=myalong]
to[manoooh curve] (Y-Title.west);
fi
}
end{scope}
}
%pgfmathsetmacro{huenumm}{2*0.75*(1/totalnodes)}
%definecolor{mycolor2}{hsb}{huenumm,1,1}
%draw[-latex,mycolor2,very thick] (2-Title.east) -- ++ (3,0) to[manoooh curve=1.6] (3-Title.west);
end{tikzpicture}
flushleft
qquadparbox{0.4linewidth}{%
hypersetup{pdfborder={0 0 0}}%
% list of OCGs, space separated
defocglist{}%
foreach X in {0,...,totalnodes} {xdefocglist{ocglistspace myArrowX}}
fbox{%
parbox{12cm}{%
% on/off All
showocg{ocglist}{fboxsep=1ptfbox{rule{0pt}{1.7ex}on}}/%
hideocg{ocglist}{fboxsep=1ptfbox{rule{0pt}{1.7ex}off}} All\%
% checkboxes
foreach X in {0,...,totalnodes} {%
layerCheckBox{}{myArrowX}{on}begin{tikzpicture}[baseline=-1ex]%
pgfmathsetmacro{huenum}{X*0.75*(1/totalnodes)}%
definecolor{mycolor}{hsb}{huenum,1,1}draw[-latex,mycolor,very thick] (0,0) -- (1,0);%
end{tikzpicture}qquad%
}%
}
}
}
end{document}
It works fantastic.
Now I want to add another arrow, that goes from (2)
to (3)
, so one would probably add
"{3}",
to the LstCon
object (please increment the value of totalnodes
by 1!), but this produces an ugly output, because it collides with "Subject1".
To fix this, I have been told that I need to create this new arrow outside the foreach
loop that it is inside the tikzpicture
environment. So I have deleted "{3}",
and added the following three lines to the code:
pgfmathsetmacro{huenumm}{2*0.75*(1/totalnodes)}
definecolor{mycolor2}{hsb}{huenumm,1,1}
draw[-latex,mycolor2,very thick] -- ++ (3,0) (2-Title.east) to[manoooh curve=1.6] (3-Title.west);
You only need to uncomment that lines of the given MWE to get this output:
It looks like there are no problems.
However, adding that arrow outside the foreach
loop makes the checkbox of it non-clickable:
I want to make it possible to click on this new checkbox. How can we do it?
Thanks!!
P.S. Also I am getting an overfull hbox
bad box message because of the parbox
. Could you consider try to find out why I am getting it?
tikz-pgf ocgx2
add a comment |
This is an addendum of a previous question: How to put a box and use columns to separate arrows.
Please consider this MWE (adapted from a nice answer of that question):
documentclass{article}
usepackage[margin=0in,footskip=0in]{geometry}
usepackage[english]{babel}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{hyperref}
usepackage[tikz]{ocgx2}
usepackage{amssymb} % checkmark
% check box command for layer switching
newcommandlayerCheckBox[3]{%
% #1: switch id, if empty use #2 instead
% #2: layer ids to be toggled (space separated if multiple ids),
% #3: initial visibility
resizebox{2ex}{!}{%
ooalign{%
switchocg{#1 #2}{$square$}cr%
begin{ocg}{%
ifxnil#1nil#2else#1fi%
}%
{%
ifxnil#1nil#2else#1fi%
}{#3}$checkmark$%
end{ocg}%
}%
}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
usepackage{tikz}
usetikzlibrary{positioning,fit,calc}
pgfdeclarelayer{behind}
pgfdeclarelayer{background}
pgfdeclarelayer{foreground}
pgfsetlayers{behind,background,main,foreground}
tikzset{
text field/.style={text height=1.5ex,align=center,rounded corners},
nonfillable title field/.style={text height=2ex,text depth=0.3em,anchor=south,text
width=5cm,align=center,font=footnotesizesffamily},
pics/nonfillable subject/.style={code={%
node[text field] (-TF)
{hspace{1.2em}~/~hspace{1.15em}~/~hspace{2.35em}{}};
node[nonfillable title field] (-Title)
at ([yshift=0.4em]-TF.north) {#1};
draw[rounded corners] (-TF.south west) |- (-Title.south west)
|- (-Title.north east) -- (-Title.south east) -| (-TF.south east)
-- cycle;
draw ([xshift=4pt]-Title.south west) -- ([xshift=-4pt]-Title.south east);
}},
manoooh/.style={column sep=-1.75cm,row sep=5mm},
fit sep/.initial=4pt, % change width of node (big rectangle shape)
fit dist/.initial=40pt, % change node distance (big rectangle shape)
inlay top sep/.initial=24pt,
matrix top sep/.initial=24pt,
manoooh curve/.style={to path={let p1=($(tikztotarget)-(tikztostart)$)
in (tikztostart) .. controls ($(tikztostart)+(#1*x1,0)$)
and ($(tikztotarget)+(-#1*x1,0)$) .. (tikztotarget)}},
manoooh curve/.default=0.3,
along node/.style={insert path={
to[out=0,in=180]
([yshift=5pt]#1-Title.north west) -- ([yshift=5pt]#1-Title.north east)}}
} % From https://tex.stackexchange.com/a/478723/152550
makeatletter% from https://tex.stackexchange.com/a/85531/121799
longdefifnodedefined#1#2#3{%
@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%
newcommandtotalnodes{1} % Define the total of subjects that need arrows-1
%%%%%%%%%%%%%%%%%%%%%%%%%
begin{document}
ifdefinedmymatbottom
else
typeout{Pleasespace recompilespace yourspace file!}
defmymatbottom{-150pt}
fi
ifdefinedmyheight
else
defmyheight{0}
typeout{Pleasespace recompilespace yourspace file!}
fi
ifdefinedLstMatYShifts
else
defLstMatYShifts{{0pt,0pt,0pt,0pt,0pt,0pt,0pt}}
fi
ifdefinedLstMatXShifts
else
defLstMatXShifts{{0pt,0pt,0pt,0pt,0pt,0pt,0pt}}
fi
begin{tikzpicture}
% step 1: add the matrices, name them mat0, mat1 etc.
begin{scope}[local bounding box=matrices]
matrix[manoooh] (mat0) at ({LstMatXShifts[0]},{LstMatYShifts[0]}) {
pic[local bounding box=A] (0) {nonfillable subject={Subject0}}; & &
pic (1) {nonfillable subject={Subject1}}; \
& pic (2) {nonfillable subject={Subject2}}; & \
};
matrix[manoooh] (mat1) at ({LstMatXShifts[1]},{LstMatYShifts[1]}) {
pic (3) {nonfillable subject={Subject3}}; \
pic (4) {nonfillable subject={Subject4}}; \
pic (5) {nonfillable subject={Subject5}}; \
pic (6) {nonfillable subject={Subject6}}; \
pic (7) {nonfillable subject={Subject7}}; \
pic (8) {nonfillable subject={Subject8}}; \
};
end{scope}
pgfmathsetmacro{groupwidth}{0}
pgfmathsetmacro{lastwidth}{0}
foreach X in {0,...,1}{ %<- if you have more or less matrices, adjust 3
ifnodedefined{matEX}
{
% has inlay
}
{
% no inlay
path
let p1=($(matX.north east)-(matX.south west)$),
n1={max(abs(y1)/2,mymatbottom)}
in
pgfextra{xdefmymatbottom{n1}
ifnumX=0
pgfmathsetmacro{groupwidth}{0}
else
pgfmathsetmacro{groupwidth}{groupwidth+x1/2+lastwidth/2+pgfkeysvalueof{/tikz/fit dist}}
fi
xdefgroupwidth{groupwidth}
xdeflastwidth{x1}
pgfmathsetmacro{myheight}{max(y1+pgfkeysvalueof{/tikz/matrix top sep},myheight)}
xdefmyheight{myheight}
ifnumX=0
xdefLstMatYShifts{0pt}
xdefLstMatXShifts{0pt}
else
xdefLstMatYShifts{LstMatYShifts,0pt}
xdefLstMatXShifts{LstMatXShifts,groupwidth pt}
fi};
% the fit parameters determine the shape of the background rectangles
}
}
makeatletter
immediatewrite@mainaux{xdefstringmymatbottom{-mymatbottom}relax}
immediatewrite@mainaux{xdefstringmyheight{myheight}relax}
immediatewrite@mainaux{xdefstringLstMatYShifts{{LstMatYShifts}}relax}
immediatewrite@mainaux{xdefstringLstMatXShifts{{LstMatXShifts}}relax}
makeatother
% From https://tex.stackexchange.com/a/480685/152550
% now add the arrows.
gdefLstCon{%
{
"{6/1}",
"{4}",
}
}
pgfmathsetmacro{mylst}{LstCon[0]}
foreach X in {0,...,totalnodes} {
begin{scope}[ocg={name={ArrowX},ref=myArrowX,status=visible}]
pgfmathsetmacro{huenum}{X*0.75*(1/totalnodes)}
definecolor{mycolor}{hsb}{huenum,1,1}
pgfmathsetmacro{mylst}{LstCon[X]}
%typeout{X:mylst}
foreach Y/myalong in mylst {
ifxmyalongY
%typeout{X:Y,empty}
draw[-latex,mycolor,very thick] (X-Title.east)
to[manoooh curve] (Y-Title.west);
else
%typeout{X:Yspace andspace myalong}
draw[-latex,mycolor,very thick] (X-Title.east)
[along node/.list/.expanded=myalong]
to[manoooh curve] (Y-Title.west);
fi
}
end{scope}
}
%pgfmathsetmacro{huenumm}{2*0.75*(1/totalnodes)}
%definecolor{mycolor2}{hsb}{huenumm,1,1}
%draw[-latex,mycolor2,very thick] (2-Title.east) -- ++ (3,0) to[manoooh curve=1.6] (3-Title.west);
end{tikzpicture}
flushleft
qquadparbox{0.4linewidth}{%
hypersetup{pdfborder={0 0 0}}%
% list of OCGs, space separated
defocglist{}%
foreach X in {0,...,totalnodes} {xdefocglist{ocglistspace myArrowX}}
fbox{%
parbox{12cm}{%
% on/off All
showocg{ocglist}{fboxsep=1ptfbox{rule{0pt}{1.7ex}on}}/%
hideocg{ocglist}{fboxsep=1ptfbox{rule{0pt}{1.7ex}off}} All\%
% checkboxes
foreach X in {0,...,totalnodes} {%
layerCheckBox{}{myArrowX}{on}begin{tikzpicture}[baseline=-1ex]%
pgfmathsetmacro{huenum}{X*0.75*(1/totalnodes)}%
definecolor{mycolor}{hsb}{huenum,1,1}draw[-latex,mycolor,very thick] (0,0) -- (1,0);%
end{tikzpicture}qquad%
}%
}
}
}
end{document}
It works fantastic.
Now I want to add another arrow, that goes from (2)
to (3)
, so one would probably add
"{3}",
to the LstCon
object (please increment the value of totalnodes
by 1!), but this produces an ugly output, because it collides with "Subject1".
To fix this, I have been told that I need to create this new arrow outside the foreach
loop that it is inside the tikzpicture
environment. So I have deleted "{3}",
and added the following three lines to the code:
pgfmathsetmacro{huenumm}{2*0.75*(1/totalnodes)}
definecolor{mycolor2}{hsb}{huenumm,1,1}
draw[-latex,mycolor2,very thick] -- ++ (3,0) (2-Title.east) to[manoooh curve=1.6] (3-Title.west);
You only need to uncomment that lines of the given MWE to get this output:
It looks like there are no problems.
However, adding that arrow outside the foreach
loop makes the checkbox of it non-clickable:
I want to make it possible to click on this new checkbox. How can we do it?
Thanks!!
P.S. Also I am getting an overfull hbox
bad box message because of the parbox
. Could you consider try to find out why I am getting it?
tikz-pgf ocgx2
This is an addendum of a previous question: How to put a box and use columns to separate arrows.
Please consider this MWE (adapted from a nice answer of that question):
documentclass{article}
usepackage[margin=0in,footskip=0in]{geometry}
usepackage[english]{babel}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{hyperref}
usepackage[tikz]{ocgx2}
usepackage{amssymb} % checkmark
% check box command for layer switching
newcommandlayerCheckBox[3]{%
% #1: switch id, if empty use #2 instead
% #2: layer ids to be toggled (space separated if multiple ids),
% #3: initial visibility
resizebox{2ex}{!}{%
ooalign{%
switchocg{#1 #2}{$square$}cr%
begin{ocg}{%
ifxnil#1nil#2else#1fi%
}%
{%
ifxnil#1nil#2else#1fi%
}{#3}$checkmark$%
end{ocg}%
}%
}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
usepackage{tikz}
usetikzlibrary{positioning,fit,calc}
pgfdeclarelayer{behind}
pgfdeclarelayer{background}
pgfdeclarelayer{foreground}
pgfsetlayers{behind,background,main,foreground}
tikzset{
text field/.style={text height=1.5ex,align=center,rounded corners},
nonfillable title field/.style={text height=2ex,text depth=0.3em,anchor=south,text
width=5cm,align=center,font=footnotesizesffamily},
pics/nonfillable subject/.style={code={%
node[text field] (-TF)
{hspace{1.2em}~/~hspace{1.15em}~/~hspace{2.35em}{}};
node[nonfillable title field] (-Title)
at ([yshift=0.4em]-TF.north) {#1};
draw[rounded corners] (-TF.south west) |- (-Title.south west)
|- (-Title.north east) -- (-Title.south east) -| (-TF.south east)
-- cycle;
draw ([xshift=4pt]-Title.south west) -- ([xshift=-4pt]-Title.south east);
}},
manoooh/.style={column sep=-1.75cm,row sep=5mm},
fit sep/.initial=4pt, % change width of node (big rectangle shape)
fit dist/.initial=40pt, % change node distance (big rectangle shape)
inlay top sep/.initial=24pt,
matrix top sep/.initial=24pt,
manoooh curve/.style={to path={let p1=($(tikztotarget)-(tikztostart)$)
in (tikztostart) .. controls ($(tikztostart)+(#1*x1,0)$)
and ($(tikztotarget)+(-#1*x1,0)$) .. (tikztotarget)}},
manoooh curve/.default=0.3,
along node/.style={insert path={
to[out=0,in=180]
([yshift=5pt]#1-Title.north west) -- ([yshift=5pt]#1-Title.north east)}}
} % From https://tex.stackexchange.com/a/478723/152550
makeatletter% from https://tex.stackexchange.com/a/85531/121799
longdefifnodedefined#1#2#3{%
@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%
newcommandtotalnodes{1} % Define the total of subjects that need arrows-1
%%%%%%%%%%%%%%%%%%%%%%%%%
begin{document}
ifdefinedmymatbottom
else
typeout{Pleasespace recompilespace yourspace file!}
defmymatbottom{-150pt}
fi
ifdefinedmyheight
else
defmyheight{0}
typeout{Pleasespace recompilespace yourspace file!}
fi
ifdefinedLstMatYShifts
else
defLstMatYShifts{{0pt,0pt,0pt,0pt,0pt,0pt,0pt}}
fi
ifdefinedLstMatXShifts
else
defLstMatXShifts{{0pt,0pt,0pt,0pt,0pt,0pt,0pt}}
fi
begin{tikzpicture}
% step 1: add the matrices, name them mat0, mat1 etc.
begin{scope}[local bounding box=matrices]
matrix[manoooh] (mat0) at ({LstMatXShifts[0]},{LstMatYShifts[0]}) {
pic[local bounding box=A] (0) {nonfillable subject={Subject0}}; & &
pic (1) {nonfillable subject={Subject1}}; \
& pic (2) {nonfillable subject={Subject2}}; & \
};
matrix[manoooh] (mat1) at ({LstMatXShifts[1]},{LstMatYShifts[1]}) {
pic (3) {nonfillable subject={Subject3}}; \
pic (4) {nonfillable subject={Subject4}}; \
pic (5) {nonfillable subject={Subject5}}; \
pic (6) {nonfillable subject={Subject6}}; \
pic (7) {nonfillable subject={Subject7}}; \
pic (8) {nonfillable subject={Subject8}}; \
};
end{scope}
pgfmathsetmacro{groupwidth}{0}
pgfmathsetmacro{lastwidth}{0}
foreach X in {0,...,1}{ %<- if you have more or less matrices, adjust 3
ifnodedefined{matEX}
{
% has inlay
}
{
% no inlay
path
let p1=($(matX.north east)-(matX.south west)$),
n1={max(abs(y1)/2,mymatbottom)}
in
pgfextra{xdefmymatbottom{n1}
ifnumX=0
pgfmathsetmacro{groupwidth}{0}
else
pgfmathsetmacro{groupwidth}{groupwidth+x1/2+lastwidth/2+pgfkeysvalueof{/tikz/fit dist}}
fi
xdefgroupwidth{groupwidth}
xdeflastwidth{x1}
pgfmathsetmacro{myheight}{max(y1+pgfkeysvalueof{/tikz/matrix top sep},myheight)}
xdefmyheight{myheight}
ifnumX=0
xdefLstMatYShifts{0pt}
xdefLstMatXShifts{0pt}
else
xdefLstMatYShifts{LstMatYShifts,0pt}
xdefLstMatXShifts{LstMatXShifts,groupwidth pt}
fi};
% the fit parameters determine the shape of the background rectangles
}
}
makeatletter
immediatewrite@mainaux{xdefstringmymatbottom{-mymatbottom}relax}
immediatewrite@mainaux{xdefstringmyheight{myheight}relax}
immediatewrite@mainaux{xdefstringLstMatYShifts{{LstMatYShifts}}relax}
immediatewrite@mainaux{xdefstringLstMatXShifts{{LstMatXShifts}}relax}
makeatother
% From https://tex.stackexchange.com/a/480685/152550
% now add the arrows.
gdefLstCon{%
{
"{6/1}",
"{4}",
}
}
pgfmathsetmacro{mylst}{LstCon[0]}
foreach X in {0,...,totalnodes} {
begin{scope}[ocg={name={ArrowX},ref=myArrowX,status=visible}]
pgfmathsetmacro{huenum}{X*0.75*(1/totalnodes)}
definecolor{mycolor}{hsb}{huenum,1,1}
pgfmathsetmacro{mylst}{LstCon[X]}
%typeout{X:mylst}
foreach Y/myalong in mylst {
ifxmyalongY
%typeout{X:Y,empty}
draw[-latex,mycolor,very thick] (X-Title.east)
to[manoooh curve] (Y-Title.west);
else
%typeout{X:Yspace andspace myalong}
draw[-latex,mycolor,very thick] (X-Title.east)
[along node/.list/.expanded=myalong]
to[manoooh curve] (Y-Title.west);
fi
}
end{scope}
}
%pgfmathsetmacro{huenumm}{2*0.75*(1/totalnodes)}
%definecolor{mycolor2}{hsb}{huenumm,1,1}
%draw[-latex,mycolor2,very thick] (2-Title.east) -- ++ (3,0) to[manoooh curve=1.6] (3-Title.west);
end{tikzpicture}
flushleft
qquadparbox{0.4linewidth}{%
hypersetup{pdfborder={0 0 0}}%
% list of OCGs, space separated
defocglist{}%
foreach X in {0,...,totalnodes} {xdefocglist{ocglistspace myArrowX}}
fbox{%
parbox{12cm}{%
% on/off All
showocg{ocglist}{fboxsep=1ptfbox{rule{0pt}{1.7ex}on}}/%
hideocg{ocglist}{fboxsep=1ptfbox{rule{0pt}{1.7ex}off}} All\%
% checkboxes
foreach X in {0,...,totalnodes} {%
layerCheckBox{}{myArrowX}{on}begin{tikzpicture}[baseline=-1ex]%
pgfmathsetmacro{huenum}{X*0.75*(1/totalnodes)}%
definecolor{mycolor}{hsb}{huenum,1,1}draw[-latex,mycolor,very thick] (0,0) -- (1,0);%
end{tikzpicture}qquad%
}%
}
}
}
end{document}
It works fantastic.
Now I want to add another arrow, that goes from (2)
to (3)
, so one would probably add
"{3}",
to the LstCon
object (please increment the value of totalnodes
by 1!), but this produces an ugly output, because it collides with "Subject1".
To fix this, I have been told that I need to create this new arrow outside the foreach
loop that it is inside the tikzpicture
environment. So I have deleted "{3}",
and added the following three lines to the code:
pgfmathsetmacro{huenumm}{2*0.75*(1/totalnodes)}
definecolor{mycolor2}{hsb}{huenumm,1,1}
draw[-latex,mycolor2,very thick] -- ++ (3,0) (2-Title.east) to[manoooh curve=1.6] (3-Title.west);
You only need to uncomment that lines of the given MWE to get this output:
It looks like there are no problems.
However, adding that arrow outside the foreach
loop makes the checkbox of it non-clickable:
I want to make it possible to click on this new checkbox. How can we do it?
Thanks!!
P.S. Also I am getting an overfull hbox
bad box message because of the parbox
. Could you consider try to find out why I am getting it?
tikz-pgf ocgx2
tikz-pgf ocgx2
asked 7 mins ago
manoooohmanooooh
1,1731517
1,1731517
add a comment |
add a comment |
0
active
oldest
votes
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482674%2fhow-to-add-a-particular-object-to-an-ocg-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482674%2fhow-to-add-a-particular-object-to-an-ocg-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown