Shapepar 段落最后一行居中

Shapepar 段落最后一行居中

我有一段文字,\shapepar想让它紧紧围绕自定义形状(背景图像)。文字本身两端对齐,但我想让最后一行居中。可以吗?

段落的内容是从外部数据源生成的,我需要生成大量这样的文档,因此无法手动调整 - 它需要自动进行。

我的代码:

\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}

结果与期望结果: 结果 通缉

答案1

现在破解shapepar内部结构有点晚了,但是手动修复这个问题很容易,而且获得一个好的位置也许需要手动控制来与边框交互:

在此处输入图片描述

\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}

答案2

最后我选择了,\parshape\shapepar它在 TikZ 中不起作用。因此我使用background包来获取背景图像,并picture使用 环境 进行绝对定位。

结果

\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}

相关内容