
我需要幫助編寫範例環境。我只是希望它看起來像下圖,這是我從圖書館裡的一本舊書中摘下來的。
這就是我所做的。
\newtheorem{exem}{EXAMPLE}
\newenvironment{ex}{\parshape=3
0\textwidth \textwidth
0.25\textwidth 0.74\textwidth
0pt \textwidth \begin{exem} \rm \hspace{0.2cm}}{\end{exem}}
\begin{document}
\begin{ex}
Text
\end{ex}
\end{document}
但是,當定義的環境中文字很長時,此程式碼會失敗。然後我開始遇到右邊距問題。我不知道如何解決它。請問,你能幫我定義那個環境嗎?
答案1
這是一個example
使用以下指令設定段落對齊/形狀的環境\parshape
:
\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newcounter{example}
\newcommand{\examplename}{\textsc{Example}}
\makeatletter
\newenvironment{example}
{\refstepcounter{example}% Step example counter
\sbox\@tempboxa{\examplename~\theexample.~}% Store environment title
% Set paragraph alignment
\parshape 3 \wd\@tempboxa \dimexpr\linewidth-\wd\@tempboxa % Line 1
\wd\@tempboxa \dimexpr\linewidth-\wd\@tempboxa % Line 2
0pt \linewidth% Line 3+
\noindent% No indent
\leavevmode% Start paragraph
\llap{\usebox\@tempboxa}% Insert environment title
\ignorespaces}% Remove spaces
{\par}
\begin{document}
\lipsum[1]
\begin{example}
\lipsum[2]
\end{example}
\lipsum[3]
\begin{example}
Some example content
\end{example}
\begin{example}
Some more example content
\end{example}
\lipsum[4]
\end{document}