# Center last line of shapepar paragraph

I have a paragraph of text inside \shapepar to make it flow tightly around a custom shape (background image). The text itself is justified to both ends, however I would like to center the last line. Is that possible?

The contents of the paragraph are generated from an external data source and I need to generate lots of documents like this, so manual adjusting is not possible - it needs to happen automatically.

My code:

\documentclass[border=0,margin=0,multi,tikz]{standalone}
\usepackage{graphicx}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{shapepar}

\def\myshapepar#1{\shapepar[1mm]{\myshapeshape}#1\par}
\def\myshapeshape{%
{0}
{0}b{0}\\
{0}t{-20}{40}\\
{5}t{-21}{42}\\
{10}t{-26}{52}\\
{15}t{-32}{64}\\
{20}t{-32}{64}\\
{25}t{-24}{48}\\
{25}e{0}
}
\begin{document}
\begin{tikzpicture}
\draw[draw=none] (0,0) rectangle (105mm, 148mm); % Force page size
\node[inner sep=0,anchor=south west] at (0,0) {\includegraphics[height=148mm]{vlocka-plain.jpg}};

\node[draw=none,align=center,text width=4cm,anchor=north] at (55mm, 120mm) {\myshapepar{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eget viverra orci. Sed lacinia maximus urna lobortis semper. Vestibulum a semper ante.}};
\end{tikzpicture}
\end{document}


Result vs. wanted result:

It's a bit late at night for hacking shapepar internals but it is easy enough to fix this manually, and getting a good position perhaps needs manual control anyway to interact with the border:

\documentclass[border=0,margin=0,multi,tikz]{standalone}
\usepackage{graphicx}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{shapepar}

\def\myshapepar#1{\shapepar[1mm]{\myshapeshape}#1\par}
\def\myshapeshape{%
{0}
{0}b{0}\\
{0}t{-20}{40}\\
{5}t{-21}{42}\\
{10}t{-26}{52}\\
{15}t{-32}{64}\\
{20}t{-32}{64}\\
{25}t{-24}{48}\\
{25}e{0}
}
\begin{document}
\begin{tikzpicture}
\draw[draw=none] (0,0) rectangle (105mm, 148mm); % Force page size
\node[inner sep=0,anchor=south west] at (0,0) {%
%\includegraphics[height=148mm]{vlocka-plain.jpg}%
};

\node[draw=none,align=center,text width=4cm,anchor=north] at (55mm, 120mm) {\myshapepar{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eget viverra orci. Sed lacinia maximus urna lobortis semper.
\mbox{\hspace{1cm}Vestibulum a semper ante.}}};
\end{tikzpicture}
\end{document}

• instead of a fixed distance of 1cm (which looks not quite centered to me), wouldn't \hspace*{\fil} work to counteract the 1fil in the usual \parfillskip? – barbara beeton Nov 18 '15 at 16:25
• @barbarabeeton no doesn't work as Donald is doing all kinds of measuring boxing unboxing and re-setting to make shapepar work, and a stretchable glue looks like 0pt as natural width most of the time so doesn't do anything useful (I tried that first:-) – David Carlisle Nov 18 '15 at 16:34
• thanks for explanation. it seemed worth asking. (so ultimately, it's a matter of getting out the measuring device and doing it manually. 1cm is definitely not quite enough.) – barbara beeton Nov 18 '15 at 16:42
• @barbarabeeton yes or actually since the border is in fact symmetrical here it's probably easier not to use shapepar at all and just use \centering with \\  to force line breaks as required. – David Carlisle Nov 18 '15 at 16:47
• @lacop since the image border is a fixed size you could probably more easily use \parshape directly (then it's easy to center each line within that shape) otherwise it's back to hacking shapepar code but that needs a free weekend and lots of coffee:-) – David Carlisle Nov 18 '15 at 23:27

In the end I went with \parshape instead of \shapepar, which didn't work in TikZ. So I used the background package for background image and picture enviroment for absolute positioning.

\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{graphicx}
\usepackage{fontspec}
\usepackage{background}
\usepackage{pst-barcode}
\usepackage{picture,rotating}
\pagenumbering{gobble}

\backgroundsetup{
scale=1,
color=black,
opacity=1,
placement=top,
vshift=-1cm,
angle=0,
contents={%
\includegraphics[width=0.99\paperwidth]{vlocka-plain-crop.jpg}
}%
}

\newlength{\halfpage}
\setlength{\halfpage}{\dimexpr(\textwidth)/2\relax}
\newcommand{\shapeline}[1]{\dimexpr(\halfpage-\dimexpr(#1)/2) #1}

\begin{document}
\begin{picture}(0,0)
\put(-0.375in,-6.3cm){
\begin{pspicture}(1,1)
\psbarcode{http://example.com/?code=code}{eclevel=L width=0.75 height=0.75}{qrcode}
\end{pspicture}
\put(1cm,1.75cm){\turnbox{-90}{\textbf{code}}}
}
\end{picture}%
~\\[22pt]
\centering \textbf{Some title} % Nadpis priania
\\[10pt]
\begin{center}%
\parshape=6
\shapeline{120pt}
\shapeline{140pt}
\shapeline{155pt}
\shapeline{180pt}
\shapeline{200pt}
\shapeline{175pt}
a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
\end{center}%
\end{document}

• Isn't there any automatic way to do it without manually specifying the coordinates? – skan Feb 7 '17 at 17:06