我尝试使用 wrapfig 包将左侧的一个小表格和右侧的图形排列在一行中,同时文本浮动在它们周围,但失败了。
我的代码是:
\documentclass[10pt]{article}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows,calc,intersections,through}
\begin{document}
\begin{wrapfigure}[4]{l}{0.3\textwidth}
\centering
\begin{tabular}[c]{|c|c|}
\hline Score & Teacher \\[-0.5mm]
\hline & \\[3mm]
\hline
\end{tabular}
\end{wrapfigure}
\lipsum[1]
\begin{wrapfigure}{r}{0.3\textwidth}%
\centering
\begin{tikzpicture}[scale=0.7]
\begin{scriptsize}
\coordinate [label=-135:{$A$}] (A) at (0,0);
\coordinate [label=-45:{$B$}] (B) at (3,0);
\coordinate [label=0:{$C$}] (C) at ($(3,0)+(60:3)$);
\coordinate [label=135:{$D$}] (D) at (60:3);
\coordinate [label=-90:{$E$}] (E) at (2.7,0);
\coordinate [label=180:{$F$}] (F) at (60:2);
\coordinate [label=0:{$G$}] (G) at ($(B)!(F)!(C)$);
\draw (A)--(B)--(C)--(D)--cycle;
\draw (E)--(F)--(G);
\end{scriptsize}
\end{tikzpicture}
\caption{}
\end{wrapfigure}
\lipsum[2]
\lipsum[3-4]
\end{document}
输出如下:
关于如何让表格和图形水平对齐,同时文本仍然在它们周围浮动,有什么想法吗?
答案1
wrapfig
实际上并不支持同一行上的两个图形,但是如果我们简化事情并只考虑单个段落足够大以进行剪切的情况,并且我们不必执行巧妙的延续段落代码,那么您只需wrapfig
测量两个图像并制作一个\parshape
适合它们的图像即可。
\documentclass[10pt]{article}
\usepackage{wrapfig}
\usepackage{lipsum,capt-of}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows,calc,intersections,through}
\begin{document}
\sbox0{\begin{tabular}[c]{|c|c|}
\hline Score & Teacher \\[-0.5mm]
\hline & \\[3mm]
\hline
\end{tabular}}
\sbox2{\begin{minipage}{0.3\textwidth}%
\centering
\begin{tikzpicture}[scale=0.7]
\begin{scriptsize}
\coordinate [label=-135:{$A$}] (A) at (0,0);
\coordinate [label=-45:{$B$}] (B) at (3,0);
\coordinate [label=0:{$C$}] (C) at ($(3,0)+(60:3)$);
\coordinate [label=135:{$D$}] (D) at (60:3);
\coordinate [label=-90:{$E$}] (E) at (2.7,0);
\coordinate [label=180:{$F$}] (F) at (60:2);
\coordinate [label=0:{$G$}] (G) at ($(B)!(F)!(C)$);
\draw (A)--(B)--(C)--(D)--cycle;
\draw (E)--(F)--(G);
\end{scriptsize}
\end{tikzpicture}
\captionof{figure}{}
\end{minipage}}
\dimen4=\dimexpr\wd0 + 1em\relax
\dimen0=\textwidth
\advance\dimen0-\dimexpr\wd2 + 1em\relax
\dimen2=\dimen0
\advance\dimen2-\dimexpr\wd0 + 1em\relax
\noindent
\smash{\hbox to \textwidth{%
\raisebox{-\height}{\box0}\hfill
\raisebox{-\height}{\box2}}}\par\vspace{-.5\baselineskip}
\setlength\emergencystretch{1em}
\parshape
10
\dimen4 \dimen2
\dimen4 \dimen2
\dimen4 \dimen2
\dimen4 \dimen2
0pt \dimen0
0pt \dimen0
0pt \dimen0
0pt \dimen0
0pt \dimen0
0pt \textwidth
\lipsum[1-4]
\end{document}