带有嵌套枚举环境的文本旁边的 TikZ 图片

带有嵌套枚举环境的文本旁边的 TikZ 图片

我有一段包含嵌套枚举环境的文本,我想将 TikZ 图片放置在该文本的右侧,以使文本不会超出图片。我尝试实施该技术这里基于picins包,它在单一enumerate环境中运行良好,但不适用于嵌套enumerate环境:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings,positioning,arrows}
\usepackage{picins}
\usepackage{mdwlist}
\usepackage{lipsum}

\textwidth=6.5in
\textheight=9.5in
\voffset=-1in
\hoffset=-1in

\begin{document}

\begin{enumerate}
\item \parpic[r]{%
    \begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
        \tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
        \tikzstyle{dampener}=[thick,decoration={markings,
          mark connection node=dmp,
          mark=at position 0.5 with
          {
            \node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
            \draw [thick] ($(dmp.north east)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
            \draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
          }
        }, decorate]
        \tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=2cm,minimum height=0.3cm]
    \node (M) [ground,anchor=north] {};
    \node[draw=none,below=1.5cm of M,inner sep=-2,minimum size=0mm] (pt1){};
    \node[circle,below=1.5cm of pt1] (pt2){$m$};
    \draw [dampener] (pt1.north) -- ($(M.south)$) node[draw=none,pos=.52,right=.4cm] {$b$};
    \draw [spring] (pt1.south) -- ($(pt2.north)$) node[draw=none,pos=.5,right=.25cm] {$k$};
    \node[draw=none,left=1.25cm of pt2,minimum size=0mm] (pt3){};
    \node[draw=none,right=1.25cm of pt2,minimum size=0mm] (pt4){};
    \node[draw=none,right=.25cm of pt2,minimum size=0mm] (pt5){};
    \node[draw=none,below=.75cm of pt5,minimum size=0mm] (pt6){};
    \draw[dashed] (pt3) -- (pt2.west);
    \draw[dashed] (pt4) -- (pt2.east);
    \begin{scope}[>=latex]
    \draw[->,thick,xshift=.25cm] (pt5) -- (pt6) node[draw=none,pos=.5,right=.15cm] {$y(t)>0$};
    \end{scope}
    \end{tikzpicture}
}%

\lipsum[66]
    \begin{enumerate}
    \item \lipsum[66]
    \item \lipsum[66]
    \end{enumerate}
\end{enumerate}
\end{document}  

在此处输入图片描述

有什么建议吗?

答案1

似乎您不需要将其添加到每个项目中,只需将其添加到嵌套枚举的第一个项目中。顺便说一句,由于 tikz 在辅助文件中保存了原点位置,因此您需要运行两次。

皮钦斯

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings,positioning,arrows}
\usepackage{picins}
\usepackage{mdwlist}
\usepackage{lipsum}

\textwidth=6.5in
\textheight=9.5in
\voffset=-1in
\hoffset=-1in

% macro creates an empty area corresponding to the remaining space.
\makeatletter
\newcommand{\emptybox}{\begingroup% preserve \@temidima and \@tempdimb
\begin{tikzpicture}[remember picture]
\pgfextractx{\@tempdima}{\pgfpointdiff{\pgfpointanchor{bottom left}{center}}
  {\pgfpointanchor{bottom right}{center}}}%
\pgfextracty{\@tempdimb}{\pgfpointdiff{\pgfpointorigin}
  {\pgfpointanchor{bottom left}{center}}}%
\ifdim\@tempdimb>0pt\relax
\else\path (0,0) (\@tempdima, \@tempdimb);
\fi
\end{tikzpicture}
\endgroup}
\makeatother

\begin{document}

\begin{enumerate}
\item \parpic[r]{%
\begin{tikzpicture}[remember picture, every node/.style={draw,outer sep=0pt,thick}]
        \tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
        \tikzstyle{dampener}=[thick,decoration={markings,
          mark connection node=dmp,
          mark=at position 0.5 with
          {
            \node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
            \draw [thick] ($(dmp.north east)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
            \draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
          }
        }, decorate]
        \tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=2cm,minimum height=0.3cm]
    \node (M) [ground,anchor=north] {};
    \node[draw=none,below=1.5cm of M,inner sep=-2,minimum size=0mm] (pt1){};
    \node[circle,below=1.5cm of pt1] (pt2){$m$};
    \draw [dampener] (pt1.north) -- ($(M.south)$) node[draw=none,pos=.52,right=.4cm] {$b$};
    \draw [spring] (pt1.south) -- ($(pt2.north)$) node[draw=none,pos=.5,right=.25cm] {$k$};
    \node[draw=none,left=1.25cm of pt2,minimum size=0mm] (pt3){};
    \node[draw=none,right=1.25cm of pt2,minimum size=0mm] (pt4){};
    \node[draw=none,right=.25cm of pt2,minimum size=0mm] (pt5){};
    \node[draw=none,below=.75cm of pt5,minimum size=0mm] (pt6){};
    \draw[dashed] (pt3) -- (pt2.west);
    \draw[dashed] (pt4) -- (pt2.east);
    \begin{scope}[>=latex]
    \draw[->,thick,xshift=.25cm] (pt5) -- (pt6) node[draw=none,pos=.5,right=.15cm] {$y(t)>0$};
    \end{scope}
    \coordinate (bottom left) at (current bounding box.south west);
    \coordinate (bottom right) at (current bounding box.south east);
    \end{tikzpicture}
}\lipsum[66]

    \begin{enumerate}
    \item \parpic[r]{\emptybox}\lipsum[66]
    \item \lipsum[66]
    \end{enumerate}
\end{enumerate}
\end{document}

相关内容