带有对话气泡的引文

带有对话气泡的引文

我正在寻找一种使用 TikZ 来实现这一点的方法:

在此处输入图片描述

但我不知道如何做这种引用风格。

\begin{sballoonquote}{\linewidth}{r}{color}{Donald Knuth}
An algorithm must be seen to be believed.
\end{sballoonquote}

生成一个右侧不规则的圆角引号,并sballoonquote*执行相同操作但不圆角。我该怎么做?有人有解决方案吗?

答案1

这里有一个解决方案,几乎完全基于 percusse 在此处发布的出色答案。

投影仪中的简单对话气泡、箭头或气球状形状

我仅将其实现为一个带有指向一个方向的箭头的命令,但这足以让你开始。

\documentclass{article}
\usepackage{kantlipsum} % for dummy text
\usepackage{calc}
\newlength{\calloutheight}
\newlength{\calloutoffset}
\newlength{\quoteheight}
\setlength{\calloutoffset}{5ex}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.callouts}
\newcommand{\calloutquote}[3][.95\textwidth]{%
% First we measure the height of the quote
% Then add the offset for the author
% The callout height is used to position to callout
% The quote height is used to reserve enough space within
% the text.  This code base almost entirely on percusse's
% answer here: https://tex.stackexchange.com/a/38872/2693
    \setbox0=\vbox{\parbox[b]{#1}{#3}}
    \setlength{\calloutheight}{\ht0+\calloutoffset}
    \setlength{\quoteheight}{\calloutheight+2\baselineskip}
    \par\vspace*{\quoteheight}
    \noindent\hfil
  \tikz[remember picture]{
        \node [anchor=base,inner sep=0,outer sep=0,
        text width=#1,align=center] (#2) {#2};
    \node[anchor=base,overlay,rectangle callout,
        callout relative pointer={(-0.3cm,-0.7cm)},
        fill=blue!30,text width=#1,align=justify]
        at ($(#2.north)+(0,\calloutheight)$) {#3};}
}


\begin{document}
Some text.
\calloutquote{Immanuel didn't really say this}{\kant[1]}

This is some text.
\calloutquote[.5\textwidth]{And he didn't say this either}{\kant[2]}
\end{document}

代码输出

答案2

我更喜欢使用 pgfkeys,因为它更容易列出参数并添加一些选项。

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts} 

\pgfkeys{%
    /calloutquote/.cd,
    width/.code                   =  {\def\calloutquotewidth{#1}},
    position/.code                =  {\def\calloutquotepos{#1}}, 
    author/.code                  =  {\def\calloutquoteauthor{#1}},
    /calloutquote/.unknown/.code   =  {\let\searchname=\pgfkeyscurrentname
                                 \pgfkeysalso{\searchname/.try=#1,                                
    /tikz/\searchname/.retry=#1},\pgfkeysalso{\searchname/.try=#1,
                                  /pgf/\searchname/.retry=#1}}
                            }  


\newcommand\calloutquote[2][]{%
       \pgfkeys{/calloutquote/.cd,
         width               = 5cm,
         position            = {(0,-1)},
         author              = {}}
  \pgfqkeys{/calloutquote}{#1}                   
  \node [rectangle callout,callout relative pointer={\calloutquotepos},text width=\calloutquotewidth,/calloutquote/.cd,
     #1] (tmpcall) at (0,0) {#2};
  \node at (tmpcall.pointer){\calloutquoteauthor};    
}  

\begin{document}
\begin{tikzpicture}
\calloutquote[author=D. Knuth,width=3cm,position={(1,-1)},fill=red!30,rounded corners]{An algorithm must be seen to be believed.}
\end{tikzpicture} 

\begin{tikzpicture}
\calloutquote[author=D. Knuth,width=0.5*\linewidth,position={(0,-1)},fill=green!30,rounded corners]{An algorithm must be seen to be believed.}
\end{tikzpicture} 

\begin{tikzpicture}
\calloutquote[author=D. Knuth,width=5cm,position={(-1,-1)},fill=blue!30,ultra thick,draw,inner sep=12pt]{An algorithm must be seen to be believed.}
\end{tikzpicture} 
\end{document} 

在此处输入图片描述

答案3

这个怎么样:

\documentclass[parskip,10pt]{scrartcl}
\usepackage[margin=10mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes,fit,backgrounds}
\usepackage{lipsum}
\usepackage{kerkis}
\usepackage{xifthen}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand{\bubble}[6]% name, content, color, align, inner sep, width
{   \ifthenelse{\equal{r}{#4}\OR\equal{c}{#4}}{\hfill}{}
    \begin{tikzpicture}
        \node[text width=\the\textwidth*#6, below right](#1){#2};
        \begin{pgfonlayer}{background}
            \node[fit=(#1),inner sep=#5,rectangle callout,rounded corners=3pt,draw,fill=#3,overlay] {};
        \end{pgfonlayer}
    \end{tikzpicture}
    \ifthenelse{\equal{l}{#4}\OR\equal{c}{#4}}{\hfill\phantom{}\\[5mm]}{\\[5mm]}
}

\begin{document}

\bubble{first}{\lipsum[1]}{blue!50}{l}{3mm}{0.9}

\bubble{second}{\lipsum[2]}{red!50}{r}{3mm}{0.7}

\bubble{second}{\lipsum[3]}{green!50}{c}{3mm}{0.5}

\bubble{third}{\lipsum[4]}{blue!50}{l}{3mm}{0.9}

\bubble{fouth}{\lipsum[5]}{red!50}{r}{3mm}{0.8}

\bubble{fouth}{\lipsum[6]}{green!50}{r}{3mm}{1.0}

\end{document}

在此处输入图片描述

相关内容