我如何创建一个带有大引号的块引用环境,类似于报价模板维基百科?
此外,最好将引号和引文都放在彩色框中,并使作者更接近引文。
答案1
这里有一个解决方案,使用TikZ
来定义使用包的新环境framed
。最好使用xelatex
或 来编译它lualatex
,因为它可以最轻松地访问各种字体。我还添加了代码使其在 下运行pdflatex
。
代码现已更新,以允许在引用的不同组成部分的格式方面具有一定的灵活性,并且环境采用两个参数:
环境语法
\begin{shadequote}[<alignment>]{<author>} text of quote \end{shadequote}
代码
% !TEX TS-program = xeLaTeX
\documentclass[12pt]{article}
\usepackage{ifxetex,ifluatex}
\usepackage{etoolbox}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usepackage{framed}
% conditional for xetex or luatex
\newif\ifxetexorluatex
\ifxetex
\xetexorluatextrue
\else
\ifluatex
\xetexorluatextrue
\else
\xetexorluatexfalse
\fi
\fi
%
\ifxetexorluatex%
\usepackage{fontspec}
\usepackage{libertine} % or use \setmainfont to choose any font on your system
\newfontfamily\quotefont[Ligatures=TeX]{Linux Libertine O} % selects Libertine as the quote font
\else
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{libertine} % or any other font package
\newcommand*\quotefont{\fontfamily{LinuxLibertineT-LF}} % selects Libertine as the quote font
\fi
\newcommand*\quotesize{60} % if quote size changes, need a way to make shifts relative
% Make commands for the quotes
\newcommand*{\openquote}
{\tikz[remember picture,overlay,xshift=-4ex,yshift=-2.5ex]
\node (OQ) {\quotefont\fontsize{\quotesize}{\quotesize}\selectfont``};\kern0pt}
\newcommand*{\closequote}[1]
{\tikz[remember picture,overlay,xshift=4ex,yshift={#1}]
\node (CQ) {\quotefont\fontsize{\quotesize}{\quotesize}\selectfont''};}
% select a colour for the shading
\colorlet{shadecolor}{Azure}
\newcommand*\shadedauthorformat{\emph} % define format for the author argument
% Now a command to allow left, right and centre alignment of the author
\newcommand*\authoralign[1]{%
\if#1l
\def\authorfill{}\def\quotefill{\hfill}
\else
\if#1r
\def\authorfill{\hfill}\def\quotefill{}
\else
\if#1c
\gdef\authorfill{\hfill}\def\quotefill{\hfill}
\else\typeout{Invalid option}
\fi
\fi
\fi}
% wrap everything in its own environment which takes one argument (author) and one optional argument
% specifying the alignment [l, r or c]
%
\newenvironment{shadequote}[2][l]%
{\authoralign{#1}
\ifblank{#2}
{\def\shadequoteauthor{}\def\yshift{-2ex}\def\quotefill{\hfill}}
{\def\shadequoteauthor{\par\authorfill\shadedauthorformat{#2}}\def\yshift{2ex}}
\begin{snugshade}\begin{quote}\openquote}
{\shadequoteauthor\quotefill\closequote{\yshift}\end{quote}\end{snugshade}}
\begin{document}
\begin{shadequote}[l]{Douglas Adams}
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
\end{shadequote}
\begin{shadequote}[r]{Douglas Adams}
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
\end{shadequote}
\begin{shadequote}[c]{Douglas Adams}
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
\end{shadequote}
\begin{shadequote}{}
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
\end{shadequote}
\end{document}
在此代码中,引号的字体独立于主文档字体设置。这是因为根据您选择的主字体,非常大的引号看起来不太好;Linux Libertine 有漂亮的引号,似乎适合此目的。如果您想将此环境与其他主文档字体一起使用,请删除/更改\usepackage{libertine}
。
示例输出
答案2
(我们刚刚收到另一个问题,询问类似问题:引用风格与 owni.eu 类似。当我开始回答这个问题时,我并没有意识到这个问题,但是当我意识到它时,我决定在这里发布我的答案。)
它也是基于 TikZ 的,但与 Alan 的版本略有不同,因为整个版本最终都以 TikZ 节点结束。这意味着它不支持分页。你也可以调整 Alan 版本中的引号,让它们看起来更好一些。
结果如下:
代码如下:
\documentclass{article}
\thispagestyle{empty}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\makeatletter
\tikzset{%
fancy quotes/.style={
text width=\fq@width pt,
align=justify,
inner sep=1em,
anchor=north west,
minimum width=\linewidth,
},
fancy quotes width/.initial={.8\linewidth},
fancy quotes marks/.style={
scale=8,
text=white,
inner sep=0pt,
},
fancy quotes opening/.style={
fancy quotes marks,
},
fancy quotes closing/.style={
fancy quotes marks,
},
fancy quotes background/.style={
show background rectangle,
inner frame xsep=0pt,
background rectangle/.style={
fill=gray!25,
rounded corners,
},
}
}
\newenvironment{fancyquotes}[1][]{%
\noindent
\tikzpicture[fancy quotes background]
\node[fancy quotes opening,anchor=north west] (fq@ul) at (0,0) {``};
\tikz@scan@one@point\pgfutil@firstofone([email protected])
\pgfmathsetmacro{\fq@width}{\linewidth - 2*\pgf@x}
\node[fancy quotes,#1] (fq@txt) at ([email protected] west) \bgroup}
{\egroup;
\node[overlay,fancy quotes closing,anchor=east] at ([email protected] east) {''};
\endtikzpicture}
\makeatother
\begin{document}
\lipsum[1]
\begin{fancyquotes}
\lipsum[1]
\end{fancyquotes}
\lipsum[1]
\end{document}
该lipsum
包仅提供一些虚拟文本。
答案3
\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage{graphicx}
\usepackage[svgnames]{xcolor}
\usepackage{framed}
\newcommand*\openquote{\makebox(25,-22){\scalebox{5}{``}}}
\newcommand*\closequote{\makebox(25,-22){\scalebox{5}{''}}}
\colorlet{shadecolor}{Azure}
\makeatletter
\newif\if@right
\def\shadequote{\@righttrue\shadequote@i}
\def\shadequote@i{\begin{snugshade}\begin{quote}\openquote}
\def\endshadequote{%
\if@right\hfill\fi\closequote\end{quote}\end{snugshade}}
\@namedef{shadequote*}{\@rightfalse\shadequote@i}
\@namedef{endshadequote*}{\endshadequote}
\makeatother
\begin{document}
\begin{shadequote}
Some quoted words
\end{shadequote}
\begin{shadequote*}
Some quoted words
\end{shadequote*}
\begin{shadequote}
A common mistake that people make when trying to design something completely
foolproof is to underestimate the ingenuity of complete fools.\par\emph{Douglas Adams}
\end{shadequote}
\end{document}
答案4
如果我知道这个问题,我就不会写了cfr-dquote
。然而,我不知道,所以我写了。这是我的软件包的一个略微修改的版本,供公众使用或拒绝。
该包定义了一个命令,\dquote[<dimension>]{<long text>}{<short text}
该命令旨在用于<dimension>
获得所需的宽度、<long text>
引用和<short text>
归属。
该封装基于 Ti钾Z 和外观可以使用常用的键值接口进行定制。例如,我从未使用过带有彩色背景的引文,但只需更改 即可轻松实现quote style
。
例如,
\documentclass[a4paper,british]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry,babel,csquotes}
\usepackage{cfr-lm}
\usepackage{cfr-dquote}
\MakeAutoQuote{‘}{’}
\MakeAutoQuote*{“}{”}
\begin{document}
\tikzset{%
dquote text font=\fontfamily{LobsterTwo-LF}\selectfont\Large\upshape,
dquote attrib font=\fontfamily{LobsterTwo-LF}\selectfont\Huge\itshape,
dquote={
quote style/.style={align=justify, fill=blue!50!cyan, fill opacity=.2, text opacity=1, text=blue!15!darkgray},
marks={
size=\Huge,
scale=4,
color=blue!50!darkgray,
opacity=.5,
},
},
}%
\dquote{%
‘Come, we shall have some fun now!’ thought Alice. ‘I'm glad they've begun asking riddles --- I believe I can guess that,’ she added aloud.
‘Do you mean that you think you can find out the answer to it?’ said the March Hare.
‘Exactly so,’ said Alice.
‘Then you should say what you mean,’ the March Hare went on.
‘I do,’ Alice hastily replied; ‘at least --- at least I mean what I say --- that's the same thing, you know.’
‘Not the same thing a bit!’ said the Hatter. ‘Why, you might just as well say that ‘I see what I eat’ is the same thing as ‘I eat what I see’!’
‘You might just as well say,’ added the March Hare, ‘that ‘I like what I get’ is the same thing as ‘I get what I like’!’
‘You might just as well say,’ added the Dormouse, which seemed to be talking in its sleep, ‘that ‘I breathe when I sleep’ is the same thing as ‘I sleep when I breathe’!’
}{Lewis Carroll}
\end{document}
产生以下输出
该包由两个文件组成,cfr-dquote.sty
和cfr-dquote.tex
。理论上,后者可以单独编译,因为它使用了standalone
类,但不要试图以这种方式使用它 - 这只是为了使调整和调试更容易。
完整代码:
\begin{filecontents}{cfr-dquote.sty}
% !TEX encoding = UTF-8 Unicode
% cfr-dquote.sty
\NeedsTeXFormat{LaTeX2e}% LaTeX 2.09 can't be used (nor non-LaTeX)
[1994/12/01]% LaTeX date must December 1994 or later
\RequirePackage{svn-prov}
\ProvidesPackageSVN{$Id: cfr-dquote.sty 7799 2018-07-20 01:52:15Z cfr $}
\RequirePackage{xcolor,pifont,standalone,xparse,tikz}
\usetikzlibrary{calc,positioning,backgrounds}
\IfFileExists{tikzlibrarypicfix.code.tex}{\usetikzlibrary{picfix}}{}
\IfFileExists{tikzlibrarycfrexternal.code.tex}{\usetikzlibrary{cfrexternal}}{\usetikzlibrary{external}}
\NewDocumentCommand\dquotetextfonthook{}{\normalfont\large}
\NewDocumentCommand\dquoteattribfonthook{}{\normalfont\normalsize}
\AtBeginDocument{%
\newlength\cfrdquoteparskip\setlength\cfrdquoteparskip{\parskip}%
\newlength\cfrdquoteparindent\setlength\cfrdquoteparindent{\parindent}}
% BEGIN defaults
\tikzset{%
dquote text font/.code={%
\RenewDocumentCommand\dquotetextfonthook{}{#1}
},
dquote attrib font/.code={%
\RenewDocumentCommand\dquoteattribfonthook{}{#1}
},
dquote/.code={%
\tikzset{%
/cfr-dquote/.cd,
#1
}
},
/cfr-dquote/quote style/.style={align=justify, color=blue!50!black},
/cfr-dquote/quote/.style={/cfr-dquote/quote style, font=\dquotetextfonthook},
/cfr-dquote/attrib/.style={/cfr-dquote/quote style, font=\dquoteattribfonthook},
/cfr-dquote/quote mark/.style={color=\cfrdquotecolor, opacity=\cfrdquoteopacity, font=\cfrdquotesize, scale=\cfrdquotescale},
/cfr-dquote/.cd,
width/.store in=\cfrdquotewidth,
text/.store in=\cfrdquotetext,
attribution/.store in=\cfrdquoteattrib,
width=120mm,
text={Does dim o gwbl yn y fan hon!},
attribution={Neb},
marks/.code={%
\tikzset{%
/cfr-dquote/quote marks/.cd,
#1
}
},
quote marks/size/.store in=\cfrdquotesize,
quote marks/scale/.store in=\cfrdquotescale,
quote marks/color/.store in=\cfrdquotecolor,
quote marks/opacity/.store in=\cfrdquoteopacity,
marks={
size=\Huge,
scale=4,
color=blue!50!cyan,
opacity=.25,
},
}
% END defaults
% BEGIN defn \dquote
\NewDocumentCommand\dquote { O {120mm} +m m }{%
\tikzset{%
external/export next=false,
/cfr-dquote/.cd,
width={#1},
text={\setlength\parskip{\cfrdquoteparskip}\setlength\parindent{\cfrdquoteparindent}#2},
attribution={#3}
}%
\input{cfr-dquote}%
}
% END defn \dquote
\endinput
\end{filecontents}
\begin{filecontents}{cfr-dquote.tex}
% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode
% arara: pdflatex: { synctex: true }
%BEGIN preamble
\csname standaloneignore\endcsname
\pdfminorversion=7
\PassOptionsToPackage{rgb}{xcolor}
\RequirePackage{svn-prov}
\ProvidesFileSVN{$Id: cfr-dquote.tex 7800 2018-07-20 01:58:28Z cfr $}
\documentclass[tikz,12pt]{standalone}
\usetikzlibrary{calc,positioning,backgrounds}
\usepackage{pifont,biblatex}
% END preamble
\begin{document}%
\begin{tikzpicture}[node distance=0pt]
\node (quotation) [/cfr-dquote/quote, text width=\cfrdquotewidth] {\cfrdquotetext};
\node (attrib) [/cfr-dquote/attrib, below=of quotation, text width=\cfrdquotewidth] {\cfrdquoteattrib};
\node (qlhs) [left=of quotation.north west, /cfr-dquote/quote mark, xshift=.25em, yshift=.25em, anchor=north east] {\ding{123}};
\node (qrhs) [right=of quotation.south east, /cfr-dquote/quote mark, xshift=-.25em, yshift=-.75em, anchor=south west] {\ding{124}};
\pgfresetboundingbox
\useasboundingbox (attrib.south -| qlhs.west) rectangle (quotation.north -| qrhs.east);
\end{tikzpicture}%
\end{document}
\end{filecontents}
\documentclass[a4paper,british]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry,babel,csquotes}
\usepackage{cfr-lm}
\usepackage{cfr-dquote}
\MakeAutoQuote{‘}{’}
\MakeAutoQuote*{“}{”}
\begin{document}
\tikzset{%
dquote text font=\fontfamily{LobsterTwo-LF}\selectfont\Large\upshape,
dquote attrib font=\fontfamily{LobsterTwo-LF}\selectfont\Huge\itshape,
dquote={
quote style/.style={align=justify, fill=blue!50!cyan, fill opacity=.2, text opacity=1, text=blue!15!darkgray},
marks={
size=\Huge,
scale=4,
color=blue!50!darkgray,
opacity=.5,
},
},
}%
\dquote{%
‘Come, we shall have some fun now!’ thought Alice. ‘I'm glad they've begun asking riddles --- I believe I can guess that,’ she added aloud.
‘Do you mean that you think you can find out the answer to it?’ said the March Hare.
‘Exactly so,’ said Alice.
‘Then you should say what you mean,’ the March Hare went on.
‘I do,’ Alice hastily replied; ‘at least --- at least I mean what I say --- that's the same thing, you know.’
‘Not the same thing a bit!’ said the Hatter. ‘Why, you might just as well say that ‘I see what I eat’ is the same thing as ‘I eat what I see’!’
‘You might just as well say,’ added the March Hare, ‘that ‘I like what I get’ is the same thing as ‘I get what I like’!’
‘You might just as well say,’ added the Dormouse, which seemed to be talking in its sleep, ‘that ‘I breathe when I sleep’ is the same thing as ‘I sleep when I breathe’!’
}{Lewis Carroll}
\end{document}