我正在尝试使用自定义环境命令(biography)来创建作者简介。代码如下
\documentclass{article}
\usepackage{graphicx}
\usepackage{{mwe}}
\newenvironment{biography}[2]{%
\footnotesize\unitlength 1mm\bigskip\parskip=0pt\par%
\rule{0pt}{39mm}\vspace{-39mm}\par% garantees correct page breaking
\noindent\setbox0\hbox{\framebox(26,32){
\includegraphics[width=27mm,height=33mm]{#1}
}}% box containing the frame
\ht0=37mm\count10=\ht0\divide\count10 by\baselineskip% calculates lines
\global\hangindent29mm\global\hangafter-\count10%
\hskip-28.5mm\setbox0\hbox to 28.5mm {\raise-30.5mm\box0\hss}%
\dp0=0mm\ht0=0mm\box0\noindent\bf#2\rm}{\par\rm\vskip9pt}
\begin{document}
\section{Authors's Profile}
\begin{biography}{example-image-10x16}{Firstname A. Lastname}
includes the biography here.
\end{biography}
\begin{biography}{example-image-10x16}{Firstname B. Lastname}
includes the biography here.
\end{biography}
\end{document}
但是,我得到了以下结果
当个人资料文本未填满图片周围的空间时,我无法编辑自定义传记环境以修复传记的位置。有人能帮我更改这个自定义命令吗?
答案1
计算合适的值\parshape
,并在必要时添加空白行来填充。
\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\makeatletter
\newenvironment{biography}[3][]{%
\sbox\z@{\includegraphics[#1]{#2}}%
\dimen@=\wd\z@
\advance\dimen@ 1em
% compute the number of lines
\count@=\ht\z@
\divide\count@ by \baselineskip
\ifdim\count@\baselineskip<\ht\z@
\advance\count@\@ne
\fi
% generate the parshape parameters
\@tempcnta=\z@ \def\bio@parshape{}%
\loop\ifnum\@tempcnta<\count@
\advance\@tempcnta\@ne
\edef\bio@parshape{\bio@parshape\dimen@\dimexpr\textwidth-\dimen@\relax}%
\repeat
\parindent\z@
\advance\count@\@ne
\parshape\count@ \bio@parshape \z@ \textwidth
\makebox[0pt][r]{%
\raisebox{\dimexpr-\height+\ht\strutbox}[0pt][0pt]{\box\z@}%
\quad
}\textbf{#3}\\\ignorespaces}
{\par
\ifnum\prevgraf<\count@
\vspace{\numexpr\count@-\prevgraf-1\relax\baselineskip}%
\fi}
\begin{document}
\section{Authors's Profile}
\begin{biography}[height=6cm,width=4cm]{example-image-10x16}{Firstname A. Lastname}
\lipsum*[2]
\end{biography}
\begin{biography}[height=6cm,width=4cm]{example-image-10x16}{Firstname B. Lastname}
\lipsum*[3-4]
\end{biography}
\end{document}
答案2
我想分享我解决这个问题的方法。我使用了该lineno
软件包,代码如下
\newcounter{biocounter}
\setcounter{biocounter}{11}
\newcount\vskipcount
\newenvironment{biography}[2]{%
\renewcommand\thelinenumber{}
\resetlinenumber[1]
\footnotesize\unitlength 1mm\bigskip\parskip=0pt\par%
\rule{0pt}{39mm}\vspace{-39mm}\par% garantees correct page breaking
\noindent\setbox0\hbox{\framebox(26,32){
\includegraphics[width=27mm,height=33mm]{#1}
}}% box containing the frame
\ht0=36mm\count10=\ht0\divide\count10 by\baselineskip% calculates lines
\global\hangindent29mm\global\hangafter-\count10%
\hskip-28.5mm\setbox0\hbox to 28.5mm {\raise-30.5mm\box0\hss}%
\begin{linenumbers}
\dp0=0mm\ht0=0mm\box0\noindent\bf#2\rm}
{\end{linenumbers}
\renewcommand\thelinenumber{\arabic{linenumber}}
\ifnum\the\value{linenumber}<\the\value{biocounter}
\vskipcount=0
\loop
\advance\vskipcount by 1
\par\rm\vskip9pt
\ifnum\vskipcount<9
\repeat
\else
\par\rm\vskip9pt
\fi
}