newenvironment、tikz 和包含图形的问题

newenvironment、tikz 和包含图形的问题

我正在尝试定义一个新环境,其目的是在图纸上显示图像和气泡并给出一些文字。

它可以产生的其中一件事是:

在此处输入图片描述

为了做到这一点,我到处找到了一些用于气泡的 LaTeX 命令(但我不得不承认我不理解它......)我将它修改为一个环境,然后我创建了我自己的环境。

以下是(错误的) LaTeX 代码:

\usepackage{graphicx}
\RequirePackage[tikz]{bclogo}
\usetikzlibrary{arrows,shapes,calc}

%to create an ellipse whose contain the text given in parameter
\newcommand{\bulle}[1]
{   \tikz   [remember picture,baseline]
                {   \node[anchor=base,inner sep=0,outer sep=0] (#1) {{}};
                    \node[overlay, ellipse callout, fill=gray!50] 
                                at ($(#1.north)+(-.5cm,0.8cm)$) {#1};
                }
}

%transform \bulle into an environment
\newenvironment{bullenv}[0]
{   \bulle\bgroup
}
{   \egroup
}

%display an image and a bubble whose position is to be adjusted
\newenvironment{advice}[3]
{   \includegraphics[scale=0.25]{#1}
    \hspace{#2}
    \vspace{#3}
    \begin{bullenv}
}
{   \end{bullenv}
}

我曾尝试这样使用它:

\begin{advice}{Images/dessin.pdf}{9cm}{3cm}
    This is my advice
\end{advice}

不幸的是,它不起作用,我不知道如何修复它......

汇编报告如下:

! Missing \endcsname inserted.
<to be read again>
\bgroup
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
! Extra \endcsname.
<argument> ...pgf@sh@sa@\tikz@fig@name \endcsname
{\pgf@sh@reanchor {\tikz@s...
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
I'm ignoring this, since I wasn't doing a \csname.
! Missing \endcsname inserted.
<to be read again>
\bgroup
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
! Missing \endcsname inserted.
<to be read again>
\bgroup
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
...
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
I'm ignoring this, since I wasn't doing a \csname.
! Package tikz Error: Giving up on this path. Did you forget a semicolon?.
See the tikz package documentation for explanation.
Type H <return> for immediate help.
...
l.36 T
his is my advice
This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.
Missing character: There is no h in font null font!
Missing character: There is no i in font null font!
Missing character: There is no s in font null font!
Missing character: There is no i in font null font!
Missing character: There is no s in font null font!
Missing character: There is no m in font null font!
Missing character: There is no y in font null font!
Missing character: There is no a in font null font!
Missing character: There is no d in font null font!
Missing character: There is no v in font null font!
Missing character: There is no i in font null font!
Missing character: There is no c in font null font!
Missing character: There is no e in font null font!
Overfull \hbox (29.01105pt too wide) in paragraph at lines 35--38
[][] []
[]
Underfull \hbox (badness 10000) in paragraph at lines 35--38
[]
[1
{/usr/local/texlive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map} <./Images/dessin.pdf>] (./essai_3.aux)
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.)

有趣的是 LaTeX 告诉我们:

假装你是赫尔克里·波洛:检查所有线索,并按顺序和方法推断真相。

如果有人有想法,我将非常感激。

答案1

在我看来,你把事情搞得太复杂了。你不需要环境。你不需要\bulle,你也不需要bullenv。你所需要的只是一个带有 4 个参数而不是 3 个参数的命令。(如果你想要更花哨,你可以创建一个键值接口,但坚持使用 4 个参数会让代码变得非常简单。)这也意味着你不需要remember picturecalc或两次运行或类似的东西。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts}
\newcommand\advice[4]
{%
  \tikz{%
    \node [inner sep=0, outer sep=0] {\includegraphics[scale=.25]{#1}};
    \node [ellipse callout, overlay, fill=gray!50] at (#2,#3) {#4}; 
  }%
}
\begin{document}
\advice{tiger}{-25mm}{-2.5mm}{This is my advice}
\end{document}

如果不需要换行符,请使用\newcommand*\advice。如果需要换行符,请将其添加align=center到调出节点的选项中。

老虎说……

相关内容