Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using MiKTeX 2.9 and XeLaTeX. I have a minipage with some formatted text:

\centering
\begin{minipage}{\quotewidth}%
    \centering\small\textit{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse elementum luctus odio sit amet mollis.}%
\end{minipage}

This is how it looks like: enter image description here

And this is what I want: enter image description here

How can I draw a polygon with exactly the same height as a text's height and with same y-coordinate?

share|improve this question

3 Answers 3

up vote 10 down vote accepted

A solution using tcolorbox; page breaks are allowed:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{most}
\usetikzlibrary{calc}
\usepackage{lipsum}

\definecolor{myblue}{RGB}{112,146,190}

\newlength\myleni
\newlength\mylenii
\newlength\quotewidth
\setlength\myleni{20pt}
\setlength\mylenii{40pt}

\newtcolorbox{mybox}{
breakable,
freelance,
remember,
colback=white,
center upper,
coltext=myblue,
left=1.5cm,
right=1.5cm,
top=0pt,
bottom=0pt,
fontupper=\itshape,
frame code={%
  \fill[myblue] let 
    \p1= (interior.north),
    \p2= (interior.south) in   
   (current page.west|-interior.north west) -- 
    ([xshift=-\myleni]interior.north west) --
    ([xshift=-\mylenii]interior.north west|-( 0,0.5*\y2+0.5*\y1 ) --
    ([xshift=-\myleni]interior.south west) --
    (current page.west|-interior.south west);
  \fill[myblue] let 
    \p1= (interior.north),
    \p2= (interior.south) in   
   (current page.east|-interior.north east) -- 
    ([xshift=\myleni]interior.north east) --
    ([xshift=\mylenii]interior.north east|-( 0,0.5*\y2+0.5*\y1 ) --
    ([xshift=\myleni]interior.south east) --
    (current page.east|-interior.south east);
  }
}

\begin{document}


\lipsum[4]
\begin{mybox}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse elementum luctus odio sit amet mollis.
\end{mybox}
\lipsum[4]

\end{document}

enter image description here

share|improve this answer
    
Thank you! It's really great and highly customizable solution, I'll defenitely use it! –  Vladimir Panchenko Feb 10 at 17:56

Here’s a solution using TikZ. Note that the quotes can't span over pages.

result

\documentclass{article}

\usepackage{environ}
\usepackage{tikz}
    \usetikzlibrary{calc}

\newlength{\quotewidth}
\setlength{\quotewidth}{0.75\textwidth}
\newlength{\bannercorner}
\setlength{\bannercorner}{2mm}
\colorlet{bannercolor}{blue!70}

\NewEnviron{bannerquote}{%
    \par\addvspace{0.5\baselineskip}\noindent
    \hfill
    \begin{tikzpicture}
        \node (quote) [
            text width = \quotewidth,
            align=center,
            font=\small\itshape,
            inner sep=0pt,
            outer xsep=2mm,
            text=bannercolor,
        ] {\BODY};
        \useasboundingbox (quote.north east) rectangle (quote.south west);
        \fill [bannercolor] (quote.north west) -- ($(quote.west)+(-\bannercorner,0)$)
            -- (quote.south west) -- ++(-\paperwidth,0) -- ++($(quote.north)-(quote.south)$)
            -- cycle;
        \fill [bannercolor] (quote.north east) -- ($(quote.east)+(\bannercorner,0)$)
            -- (quote.south east) -- ++(\paperwidth,0) -- ++($(quote.north)-(quote.south)$)
            -- cycle;
    \end{tikzpicture}
    \hfill\mbox{}%
    \par\vspace{0.5\baselineskip}%
    \noindent\ignorespaces
}


\usepackage{lipsum}% blind text

\begin{document}
\lipsum[1]

\begin{bannerquote}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse elementum luctus odio sit amet mollis.
\end{bannerquote}

\lipsum[1]



\end{document}
  • \node creats a box of with \bannerwidth containing the centered quote text.
  • \useasboundingbox make sure that the following banner won't affect placing of the box.
  • The two \fill commands draw the banner relative the the quote text contained in a node named quote.
share|improve this answer
    
Thank you, it's perfect! –  Vladimir Panchenko Feb 10 at 17:52

No tcolorbox, no tikz, and shorter that some of the other solutions. It does not break across pages, because the result is in a boxed macro, not an environment.

\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{stackengine}
\usepackage{scalerel}
\usepackage{amssymb}
\newsavebox\txbox
\newcommand\polyquote[2]{%
  \vspace{2pt}%
  \fboxsep=-0.4pt%
  \renewcommand\stacktype{L}%
  \sbox{\txbox}{\fboxsep=1pt\colorbox{white}{%
    \parbox{#1}{\color{blue!70}\centering\small\itshape#2}}}%
  {\centering%
  \hsmash{\stackon[0pt]{\colorbox{blue!70}{%
    \rule{0ex}{\ht\txbox+\dp\txbox}\hspace{\paperwidth}}}{%
    \abovebaseline[\dp\txbox]{\color{white}%
    \scaleleftright{\blacktriangleleft\kern-1.5pt}{\usebox{\txbox}}%
      {\kern-1.5pt\blacktriangleright}}}}%
  \vspace{2pt}%
  \par}%
}
\begin{document}
\lipsum[3]
\polyquote{3.5in}{%
  Lorem ipsum dolor sit amet, consectetur
  adipiscing elit. Suspendisse elementum luctus odio sit amet mollis.%
}
\lipsum[4]
\polyquote{2.5in}{%
  Lorem ipsum dolor \\sit amet, consectetur
  adipiscing\\ elit. Suspendisse\\ elementum luctus odio\\ sit amet mollis.%
}
\lipsum[4]
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.