问题

问题

以前,我在这里获得了在投影仪幻灯片中插入图像的帮助:将图像放置在框架中定义的背景层中。现在,我试图找到某种方法来确保文本不会越过背景中的倾斜白线,而无需手动插入换行符。理想情况下,结果应该是这样的

在此处输入图片描述

这是使用shapepar包装并猜测正确的形状

\newcommand{\myparshape}{
{0}
{0}b{0}\\ 
{0}t{0}{7}\\ 
{4}t{0}{5}\\
{4}e{4} 
}

\newcommand{\diagonalText}[1]{%
\begin{tikzpicture}
  \node[anchor=west,xshift=-1cm] at (2.5,2.5) {\begin{minipage}{0.5\textwidth}
        \Shapepar{\myparshape} 
        #1
        \end{minipage}
    };
\end{tikzpicture}
}

虽然上图中的解决方案看起来不错,但对于较小或较大的文本块来说却失败了

在此处输入图片描述

当文本不够时,它看起来也很奇怪。理想情况下,它应该先填满一行,然后再移动到下一行。

在此处输入图片描述

问题

  • 有没有一种半自动的方式来添加命令,以限制文本,使其不会越过上图中的白线?(解决方案是不是必须使用该parshape包,我只使用它,因为它最快地获得最接近“工作”解决方案)
  • 这也可以用于列表(枚举/逐项列出)吗?

编辑新代码解决了纯文本的问题,但改变了字体大小。此外,它仍然存在与我最初尝试相同的固有问题,它不适用于列表。

uit-背景-标题页.png

在此处输入图片描述

新代码

\documentclass[english,aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{graphicx,xcolor}

%Global Background must be put in preamble
\usebackgroundtemplate%
{%
    \includegraphics[width=\paperwidth,height=\paperheight]{uit-background-titlepage.png}%
}

\definecolor{blue}{HTML}{007396}
\colorlet{green}{green!50!black}
\definecolor{cyan}{HTML}{59BEC9}

\setbeamercolor{itemize item}{fg=cyan}
\setbeamercolor{frametitle}{fg=cyan}
\setbeamercolor{normal text}{fg=white}
\usebeamercolor*{normal text}

\usepackage{lipsum}
\usepackage{shapepar,tikz}
\usetikzlibrary{calc,fit,intersections}

\def\shapeparnodeaccuracy{2}
\newcommand\shapeparnode[6][]{
  % 6 parameters:
  % style for node (default:empty),
  % h margin, v margin, left path, right path, text (just one paragraph!)

  % name left and right paths and compute there bounding boxes
  \begin{scope}[local bounding box=leftbb]
    \path[name path global=left,xshift=#2] #4;
  \end{scope}
  \node[inner ysep=-#3,inner xsep=0pt,fit=(leftbb)](leftbb){};
  \begin{scope}[local bounding box=rightbb]
    \path[name path global=right,xshift=-#2] #5;
  \end{scope}
  \node[inner ysep=-#3,inner xsep=0pt,fit=(rightbb)](rightbb){};

  % global bounding box
  \path let
  \p1=(leftbb.north west), \p2=(leftbb.south west),
  \p3=(rightbb.north east), \p4=(rightbb.south east)
  in
  \pgfextra{
    \pgfmathsetmacro{\ymin}{(\y1 < \y3) ? \y1 : \y3}
    \pgfmathsetmacro{\ymax}{(\y2 > \y4) ? \y2 : \y4}
    \typeout{ymin \ymin}
    \typeout{ymax \ymax}
  } node[inner sep=0,fit={(\x1,\ymin pt)(\x3,\ymax pt)}](mybb){};

  % compute nb steps
  \path let \p1=(mybb.north), \p2=(mybb.south) in
  \pgfextra{
    \pgfmathsetmacro{\fnthght}{1em/\shapeparnodeaccuracy}
    \pgfmathtruncatemacro{\nbsteps}{(\y1-\y2)/\fnthght}
    \xdef\nbsteps{\nbsteps}
    \typeout{nb steps \nbsteps}
  };

  % horizontal references
  \path (mybb.north) -- (mybb.south)
  \foreach \cnt in {0,1,...,\nbsteps}{
    \pgfextra{\pgfmathsetmacro{\pos}{\cnt/\nbsteps}}
    coordinate[pos=\pos] (ref \cnt)
  };

  % left and right boundaries coordinates
  \foreach \cnt in {0,1,...,\nbsteps}{
    % an horizontal line from left to right
    \path[name path=ltor]
    (mybb.west |- ref \cnt) --  (mybb.east |- ref \cnt);
    % same line from right to left
    \path[name path=rtol]
    (mybb.east |- ref \cnt) -- (mybb.west |- ref \cnt);
    % left boundary
    \path[name intersections={of=rtol and left,by={l \cnt},sort by=rtol}];
    % right boundary
    \path[name intersections={of=ltor and right,by={r \cnt},sort by=ltor}];
  }
  % start point (and initial value of boundshape)
  \path let \p1=(l 0) in 
  \pgfextra{
    \pgfmathsetmacro{\xstart}{\x1}
    \xdef\boundshape{{0}{0}b{\xstart}}
    \xdef\xmin{\xstart}
    \xdef\xmax{\xstart}
  };

  % top and bottom
  \path let \p1=(l 0), \p2=(l \nbsteps) in
  \pgfextra{
    \pgfmathsetmacro{\ystart}{\y1}\xdef\ystart{\ystart}
    \pgfmathsetmacro{\yending}{\y2}\xdef\yending{\yending}
  };
  % incremental definition of boundshape
  \foreach \cnt in {0,1,...,\nbsteps}{
    \path let \p1=(l \cnt), \p2=(r \cnt) in
    \pgfextra{
      \pgfmathsetmacro{\start}{\x1}
      \pgfmathsetmacro{\len}{\x2-\x1}
      \pgfmathsetmacro{\ypos}{\cnt/\nbsteps*(\ystart - \yending)}
      {\let\\=\relax \xdef\boundshape{\boundshape\\{\ypos}t{\start}{\len}}}
      \pgfmathsetmacro{\xmin}{(\xmin < \start) ? \xmin : \start}
      \xdef\xmin{\xmin}
      \pgfmathsetmacro{\xmax}{(\xmax > \start + \len) ? \xmax : \start + \len}
      \xdef\xmax{\xmax}
    };
  }
  % draw the node with text in a shapepar
  \pgfmathsetmacro{\ymax}{\ystart - \yending}
  {\let\\=\relax \xdef\boundshape{\boundshape\\{\ymax}e{0}}}
  \node[#1,text width=\xmax pt - \xmin pt,align=flush left,
  anchor=north west,inner sep=0]
  at (mybb.north west -| \xmin pt,0)
  {\Shapepar[1pt]{\boundshape}#6\par};
}

% This defines the diagonal text (looking for a better solution)
\newcommand{\myparshape}{
  {0}
  {0}b{0}\\ 
  {0}t{0}{7}\\ 
  {4}t{0}{5}\\
  {4}e{4} 
}

\newcommand{\diagonalText}[1]{%
  \begin{tikzpicture}
    \node[anchor=west,xshift=-1cm] at (2.5,2.5) 
    {\begin{minipage}{0.5\textwidth}
          \Shapepar{\myparshape} 
          #1
          \end{minipage}
      };
  \end{tikzpicture}
}

\newcommand{\diagonalTextImproved}[2][]{%
  \begin{tikzpicture}
    \begin{scope} % second example (0.5855,0) -- (0.833,1)
      \small
      \def\pathone{(0,0) -- (0,-10)}%
      \def\pathtwo{(0.74685\paperwidth,0) --  (0.49\paperwidth,-10)}%
      \shapeparnode[#1]
      {0em}{1em}{\pathone}{\pathtwo}{#2}%
      %\draw[dotted,black] \pathone;
      %\draw[thick,red] \pathtwo;
    \end{scope}
  \end{tikzpicture}
}


\begin{document}

\begin{frame}{Introduction}
\begin{itemize}
\item \lipsum[75]
\item \lipsum[66]
\end{itemize}
\end{frame}

\begin{frame}{Introduction}
    \diagonalText{\lipsum[1]}
\end{frame}

\begin{frame}{Introduction}
  \diagonalTextImproved{\lipsum[1]}
\end{frame}

\begin{frame}{Introduction}
  \diagonalTextImproved{\lipsum[1]\lipsum[66]}
\end{frame}

\begin{frame}{Introduction}
  \diagonalTextImproved{\lipsum[66]}
\end{frame}

\end{document}

旧代码

\documentclass[english,aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{graphicx,xcolor}

%Global Background must be put in preamble
\usebackgroundtemplate%
{%
    \includegraphics[width=\paperwidth,height=\paperheight]{uit-background-titlepage.png}%
}

\definecolor{blue}{HTML}{007396}
\colorlet{green}{green!50!black}
\definecolor{cyan}{HTML}{59BEC9}

\setbeamercolor{itemize item}{fg=cyan}
\setbeamercolor{frametitle}{fg=cyan}
\setbeamercolor{normal text}{fg=white}
\usebeamercolor*{normal text}

\usepackage{lipsum}
\usepackage{shapepar,tikz}

% This defines the diagonal text (looking for a better solution)
\newcommand{\myparshape}{
{0}
{0}b{0}\\ 
{0}t{0}{7}\\ 
{4}t{0}{5}\\
{4}e{4} 
}

\newcommand{\diagonalText}[1]{%
\begin{tikzpicture}
  \node[anchor=west,xshift=-1cm] at (2.5,2.5) {\begin{minipage}{0.5\textwidth}
        \Shapepar{\myparshape} 
        #1
        \end{minipage}
    };
\end{tikzpicture}
}

\begin{document}

% Can one avoid that the text in this list extends beyond the white line?
\begin{frame}{Introduction}
  \begin{itemize}
    \item \lipsum[75]
    \item \lipsum[66]
  \end{itemize}
\end{frame}

% Good fit between the text and the line
\begin{frame}{Introduction}
  \diagonalText{\lipsum[1]}
\end{frame}

% Too little text, should fill a line before extending
\begin{frame}{Introduction}
  \diagonalText{\lipsum[75]}
\end{frame}

% Too much text for the parshape commands breaks the line again
\begin{frame}{Introduction}
  \diagonalText{\lipsum[1]\lipsum[66]}
\end{frame}

\end{document}

相关内容