排版思维导图目录跨越两页,在偶数页和奇数页上显示

排版思维导图目录跨越两页,在偶数页和奇数页上显示

在我的书籍项目中,我受到了以思维导图形式显示的精彩目录的启发,并作为此问题的答案发布:

使用 tikz mindmap 或类似软件制作的可视化目录

但就我而言,思维导图相当大,我想至少尝试让它跨越两页 A4 纸。为此,我碰巧找到了 Scharrer 先生对此问题的解决方案:

如何在两页上添加图片,左侧部分在左侧,右侧部分在右侧(用于书籍)?

但是,简单地将思维导图代码应用到两页图片的命令中会导致思维导图行为不连贯(甚至一侧都没有完全呈现)。我决定尝试在主文档之外生成目录,然后将其作为 .pdf 包含在内,如第二个问题的解决方案中所述。

为此,我从 Oberdiek 先生那里找到了一个解决方案,使用 zref 包:

仅导出目录

但我在以默认格式以外的格式生成导出目录时遇到了麻烦。而我想要的是 TikZ 思维导图格式。

到目前为止我得到了什么:

文件 myreport.text:

\documentclass{book}
\usepackage{zref-abspage,zref-thepage}
\makeatletter
\newcommand*{\pagevaluelabel}[1]{%
  \zref@labelbyprops{toc}{abspage}%
}
\makeatother
\AtBeginDocument{%
  \addtocontents{toc}{\string\providecommand\string\pagevaluelabel[1]{}}%
  \addtocontents{toc}{\string\pagevaluelabel{toc}}%
}
\usepackage{hyperref}

\setcounter{secnumdepth}{4}

\begin{document}

\frontmatter

Title page
\newpage

\chapter*{Foreword}

\tableofcontents

\mainmatter

\chapter{Chapter}

\section{Section}

\subsection{Subsection}

\subsubsection{Subsubsection}

\end{document}

文件 myreport-toc

\documentclass{book}

\usepackage [a3paper,%
         landscape,%
         twoside,%
         inner=2.5cm,%
         outer=2.5cm,%
         bottom=3.2cm,%
        headheight=14.5pt, % Header height
        footskip=1.4cm, % Space from the bottom margin to the baseline of the footer
        headsep=10pt, % Space from the top margin to the baseline of the header
        %showframe, % Uncomment to show how the type block is set on the page
         ] {geometry}

\usepackage{tikz}
\usetikzlibrary{mindmap}
\pagestyle{empty}

\usepackage{etoc}

\usepackage{hyperref}
\usepackage{zref-xr}
\zexternaldocument[main:]{test}\relax

\makeatletter
\newcommand*{\tocinclude}[1]{%
   \begingroup
    \makeatletter
    \def\@prj{#1}%
    \let\contentsline\foreign@contentsline
    \input{\@prj.toc}%
  \endgroup
}
\def\foreign@contentsline#1#2#3#4{%
  \ifx\\#4\\%
    \csname l@#1\endcsname{#2}{#3}%
  \else
    \ifHy@linktocpage
      \csname l@#1\endcsname{{#2}}{%
        \hyper@linkfile{#3}{\@prj.pdf}{#4}%
      }%
    \else
      \csname l@#1\endcsname{%
        \hyper@linkfile{#2}{\@prj.pdf}{#4}%
      }{#3}%
    \fi
  \fi
}%

\begin{document}
\makeatletter
\zref@refused{main:toc}
\setcounter{page}{%
  \numexpr\zref@extractdefault{main:toc}{abspage}{1}\relax
}
\renewcommand*{\thepage}{%
  \zref@extractdefault{main:thepage\number\value{page}}%
  {page}{\arabic{page}}%
}
\tocinclude{myreport}

\clearpage

\newtoks\treetok
\newtoks\parttok
\newtoks\sectiontok

\newcommand*\treenode {}  % just to check we don't overwrite something
\newcommand*\tmprotate {} % just to check we don't overwrite something
\newcommand*\tmpoption {} % just to check we don't overwrite something
\newcommand*\tmpstuff  {} % just to check we don't overwrite something

\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}

\newcommand*{\appendchildtree}[3]{% 
% this is to construct "t1 child [concept color= #3]{t2}" from #1=t1 and #2=t2
% t1 and t2 are two toks variable (not macros)
% #3 = for example teal!60
   \edef\tmpstuff {\the#1 child [concept color = #3]{\the#2}}%
   #1\expandafter {\tmpstuff }%
}

\newcounter{partco}

\etocsetstyle{part}
  {}
  {}
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
   \stepcounter{partco}%
   \ifcase\value{partco}%
   \or  \def\tmpoption {}%
        \def\tmprotate {}% first
   \or  \def\tmpoption {[concept]}%
        \def\tmprotate {[clockwise from = 60]}% second
   \else\def\tmpoption {}%
        \def\tmprotate {[counterclockwise from = 90]}% third and higher
   \fi
% define the part node
   \edef\treenode{node \tmpoption {\the\toks0. \the\toks2} \tmprotate }%
% this is a starting point which will be filled it by the section children
   \parttok\expandafter{\treenode}}
  {}

\etocsetstyle{section}
  {}
  {}
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
% define the section node
   \edef\treenode {node {\the\toks0 \space\the\toks2}}
   \sectiontok\expandafter{\treenode}%
% update current part tree with this section node, adding the correct color
   \ifcase\value{partco}%
   \or \appendchildtree\parttok\sectiontok {teal!30}% first
   \or \appendchildtree\parttok\sectiontok {yellow!40}% second
   \else\appendchildtree\parttok\sectiontok {green!30}% third etc...
   \fi }
% This updates the global tree with the data  from the
% part and all its children sections
  {\ifcase\value{partco}%
   \or \appendchildtree\treetok\parttok {teal!60}%   first
   \or \appendchildtree\treetok\parttok {yellow!80}% second
   \else\appendchildtree\treetok\parttok {green!50}% third and next ...
   \fi
   }

\etocsettocstyle
  {\treetok{\node{\textbf{My book title}} [clockwise from=60]}}
  {\global\appendtotok\treetok{ ;}}
% The \global above is mandatory because etoc always typesets TOC inside a group

\tableofcontents

%\showthe\treetok % debugging

\begin{tikzpicture}[grow cyclic, text width=2cm, 
                    align=flush center, 
                    every node/.style=concept, 
                    concept color=orange!60,
                    level 1/.style={level distance=7cm,sibling angle=120},
                    level 2/.style={level distance=4cm,sibling angle=45}]

\the\treetok
\end{tikzpicture}

\end{document}

很抱歉这不是一个简短的 MWE(甚至不是一个简短的问题),但我认为它是一个相当复杂的问题。

我想问一下,如何将这些格式信息(命令 \etocsetstyle)放入 toc 提取程序中,以便生成目录作为思维导图。最好保留超链接(但不是必须的)。任何帮助都将不胜感激,哪怕只是提醒一下应该阅读哪一部分文档,因为我无法在任何地方找到解决方案。

希望有人对此感兴趣,

托马斯·克鲁利斯

答案1

这是基于Ulrike Fischer 的回答但此处\savebox用于获取剪辑路径的坐标。它们已安装,如果您将其添加\usepackage{hyperref}到序言中,超链接将起作用。

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{mindmap,calc}
\pagestyle{empty}

\usepackage{etoc}
\newsavebox\tocbox

\begin{document}

\newtoks\treetok
\newtoks\parttok
\newtoks\sectiontok

\newcommand*\treenode {}  % just to check we don't overwrite something
\newcommand*\tmprotate {} % just to check we don't overwrite something
\newcommand*\tmpoption {} % just to check we don't overwrite something
\newcommand*\tmpstuff  {} % just to check we don't overwrite something

\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}

\newcommand*{\appendchildtree}[3]{%
% this is to construct "t1 child [concept color= #3]{t2}" from #1=t1 and #2=t2
% t1 and t2 are two toks variable (not macros)
% #3 = for example teal!60
   \edef\tmpstuff {\the#1 child [concept color = #3]{\the#2}}%
   #1\expandafter {\tmpstuff }%
}

\newcounter{partco}

\etocsetstyle{part}
  {}
  {}
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
   \stepcounter{partco}%
   \ifcase\value{partco}%
   \or  \def\tmpoption {}%
        \def\tmprotate {}% first
   \or  \def\tmpoption {[concept]}%
        \def\tmprotate {[clockwise from = 60]}% second
   \else\def\tmpoption {}%
        \def\tmprotate {[counterclockwise from = 90]}% third and higher
   \fi
% define the part node
   \edef\treenode{node \tmpoption {\the\toks0. \the\toks2} \tmprotate }%
% this is a starting point which will be filled it by the section children
   \parttok\expandafter{\treenode}}
  {}

\etocsetstyle{section}
  {}
  {}
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
% define the section node
   \edef\treenode {node {\the\toks0 \space\the\toks2}}
   \sectiontok\expandafter{\treenode}%
% update current part tree with this section node, adding the correct color
   \ifcase\value{partco}%
   \or \appendchildtree\parttok\sectiontok {teal!30}% first
   \or \appendchildtree\parttok\sectiontok {yellow!40}% second
   \else\appendchildtree\parttok\sectiontok {green!30}% third etc...
   \fi }
% This updates the global tree with the data  from the
% part and all its children sections
  {\ifcase\value{partco}%
   \or \appendchildtree\treetok\parttok {teal!60}%   first
   \or \appendchildtree\treetok\parttok {yellow!80}% second
   \else\appendchildtree\treetok\parttok {green!50}% third and next ...
   \fi
   }

\etocsettocstyle
  {\treetok{\node{\textbf{Discrete Data Analysis with R}} [clockwise from=60]}}
  {\global\appendtotok\treetok{ ;}}
% The \global above is mandatory because etoc always typesets TOC inside a group

\tableofcontents
\newcounter{nc}

\savebox\tocbox{%
\begin{tikzpicture}[grow cyclic, text width=2cm,
                    align=flush center,
                    every node/.style=concept,
                    nodes={/utils/exec=\stepcounter{nc},alias=nc-\number\value{nc}},
                    concept color=orange!60,
                    level 1/.style={level distance=7cm,sibling angle=120},
                    level 2/.style={level distance=4cm,sibling angle=45}]

\the\treetok
\path let \p1=(nc-1.east),\p2=(current bounding box.south west),
\p3=(nc-1.west),\p4=(current bounding box.north east) in 
\pgfextra{\xdef\ClipPathOne{(\x2,\y2) rectangle (\x1+5pt,\y4)}%
\xdef\ClipPathTwo{(\x3-5pt,\y2) rectangle (\x4,\y4)}};
\end{tikzpicture}}

\noindent\begin{tikzpicture}[grow cyclic, text width=2cm,
                    align=flush center,
                    every node/.style=concept,
                    concept color=orange!60,
                    level 1/.style={level distance=7cm,sibling angle=120},
                    level 2/.style={level distance=4cm,sibling angle=45}]
  \path[clip] \ClipPathOne;
\the\treetok
\end{tikzpicture}

\noindent\begin{tikzpicture}[grow cyclic, text width=2cm,
                    align=flush center,
                    every node/.style=concept,
                    concept color=orange!60,
                    level 1/.style={level distance=7cm,sibling angle=120},
                    level 2/.style={level distance=4cm,sibling angle=45}]
  \path[clip] \ClipPathTwo;
\the\treetok
\end{tikzpicture}



\part {Getting Started}
\section {Introduction}
\section {Working with Categorical Data}
\section {Discrete Distributions}


\part {Exploratory  Methods}
\section {Two-way Contingency Tables}
\section {Mosaic Displays}
\section {Correspondence Analysis}


\part {Model-building Methods}
\section {Logistic Regression Models}
\section {Polytomous Responses}
\section {Loglinear and Logit Models}
\section {Extending Loglinear Models}
\section {Generalized Linear Models}


\end{document}

在此处输入图片描述

答案2

您可以将 tikzpicture 存储在一个盒子里,然后剪辑这个盒子的各个部分。(超链接无法正常工作,因此最好禁用它们,但如果包含 pdf,您也会丢失它们)。

您也可以尝试将剪切路径直接添加到 tikzpicture,但恕我直言,获取正确的值更加困难。

代码直到\tableofcontents你链接到的答案之一,裁剪代码在后面,第一个使用图片内的路径,下一个使用框。哪个裁剪路径合理取决于你真正的思维导图。

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{mindmap}
\pagestyle{empty}

\usepackage{etoc}
\newsavebox\tocbox

\begin{document}

\newtoks\treetok
\newtoks\parttok
\newtoks\sectiontok

\newcommand*\treenode {}  % just to check we don't overwrite something
\newcommand*\tmprotate {} % just to check we don't overwrite something
\newcommand*\tmpoption {} % just to check we don't overwrite something
\newcommand*\tmpstuff  {} % just to check we don't overwrite something

\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}

\newcommand*{\appendchildtree}[3]{%
% this is to construct "t1 child [concept color= #3]{t2}" from #1=t1 and #2=t2
% t1 and t2 are two toks variable (not macros)
% #3 = for example teal!60
   \edef\tmpstuff {\the#1 child [concept color = #3]{\the#2}}%
   #1\expandafter {\tmpstuff }%
}

\newcounter{partco}

\etocsetstyle{part}
  {}
  {}
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
   \stepcounter{partco}%
   \ifcase\value{partco}%
   \or  \def\tmpoption {}%
        \def\tmprotate {}% first
   \or  \def\tmpoption {[concept]}%
        \def\tmprotate {[clockwise from = 60]}% second
   \else\def\tmpoption {}%
        \def\tmprotate {[counterclockwise from = 90]}% third and higher
   \fi
% define the part node
   \edef\treenode{node \tmpoption {\the\toks0. \the\toks2} \tmprotate }%
% this is a starting point which will be filled it by the section children
   \parttok\expandafter{\treenode}}
  {}

\etocsetstyle{section}
  {}
  {}
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
% define the section node
   \edef\treenode {node {\the\toks0 \space\the\toks2}}
   \sectiontok\expandafter{\treenode}%
% update current part tree with this section node, adding the correct color
   \ifcase\value{partco}%
   \or \appendchildtree\parttok\sectiontok {teal!30}% first
   \or \appendchildtree\parttok\sectiontok {yellow!40}% second
   \else\appendchildtree\parttok\sectiontok {green!30}% third etc...
   \fi }
% This updates the global tree with the data  from the
% part and all its children sections
  {\ifcase\value{partco}%
   \or \appendchildtree\treetok\parttok {teal!60}%   first
   \or \appendchildtree\treetok\parttok {yellow!80}% second
   \else\appendchildtree\treetok\parttok {green!50}% third and next ...
   \fi
   }

\etocsettocstyle
  {\treetok{\node{\textbf{Discrete Data Analysis with R}} [clockwise from=60]}}
  {\global\appendtotok\treetok{ ;}}
% The \global above is mandatory because etoc always typesets TOC inside a group

\tableofcontents


\savebox\tocbox{%
\begin{tikzpicture}[grow cyclic, text width=2cm,
                    align=flush center,
                    every node/.style=concept,
                    concept color=orange!60,
                    level 1/.style={level distance=7cm,sibling angle=120},
                    level 2/.style={level distance=4cm,sibling angle=45}]

\the\treetok
\end{tikzpicture}}

\noindent\begin{tikzpicture}[grow cyclic, text width=2cm,
                    align=flush center,
                    every node/.style=concept,
                    concept color=orange!60,
                    level 1/.style={level distance=7cm,sibling angle=120},
                    level 2/.style={level distance=4cm,sibling angle=45}]
  \path[clip] (0,-0.4\textheight) rectangle (\textwidth,0.4\textheight);
\the\treetok
\end{tikzpicture}


\begin{tikzpicture}
\path[clip] (0,0) rectangle (\dimexpr 0.5\wd\tocbox,\ht\tocbox);
\node[anchor=south west,inner sep=0pt] at (0,0){\usebox\tocbox};
\end{tikzpicture}

\begin{tikzpicture}
\path[clip] (\dimexpr 0.5\wd\tocbox,0) rectangle (\wd\tocbox,\ht\tocbox);
\node[anchor=south west,inner sep=0pt] at (0,0){\usebox\tocbox};
\end{tikzpicture}



\part {Getting Started}
\section {Introduction}
\section {Working with Categorical Data}
\section {Discrete Distributions}


\part {Exploratory  Methods}
\section {Two-way Contingency Tables}
\section {Mosaic Displays}
\section {Correspondence Analysis}


\part {Model-building Methods}
\section {Logistic Regression Models}
\section {Polytomous Responses}
\section {Loglinear and Logit Models}
\section {Extending Loglinear Models}
\section {Generalized Linear Models}


\end{document}

在此处输入图片描述

相关内容