如何将字符放在边距中(使用环境)

如何将字符放在边距中(使用环境)

我用它framed来创建一个小callout框,用于在书中显示提示和其他信息。虽然一切进展顺利,但我无法让图标(使用 ding)位于边距中。

目前看起来是这样的:

http://dl.dropbox.com/u/11125156/latex_sample1.png

我希望它看起来像这个模型

在此处输入图片描述

我正在使用以下代码

\documentclass[a4paper,12pt]{article}
\usepackage{verbatim}
\usepackage{color}
\usepackage[english]{babel}
\usepackage{pifont}
\usepackage[strict]{changepage}
\usepackage{framed}
\usepackage{blindtext}

\definecolor{formalshade}{rgb}{0.95,0.95,1}

\newenvironment{tipbox}{%
  \def\FrameCommand{%
  {\Huge\ding{43} }
    \hspace{1pt}%
    {\color{green}\vrule width 2pt}%
    {\color{formalshade}\vrule width 4pt}%
    \colorbox{formalshade}%
  }%
  \MakeFramed{\advance\hsize-\width\FrameRestore}%
  \noindent\hspace{-4.55pt}% disable indenting first paragraph
  \begin{adjustwidth}{}{7pt}%
  \vspace{2pt}\vspace{2pt}%
}
{%
  \vspace{2pt}\end{adjustwidth}\endMakeFramed%
}

\begin{document}

\blindtext

\begin{tipbox}
You can expect your organisation to perform better, but only if everyone pointing in the same direction.
\end{tipbox}

\blindtext

\end{document}

如果将其放在边缘太困难,只需将图标移动到框的顶部就可以了:-)

答案1

这是一个解决方案mdframed

\documentclass{article}

\usepackage{mdframed}
\usepackage{pifont}
\usepackage{xcolor}
\definecolor{formalshade}{rgb}{0.95,0.95,1}

\usepackage{lipsum}

\newmdenv[
  skipabove=\topskip,
  skipbelow=\topskip,
  innermargin=0pt,
  outermargin=0pt,
  innerleftmargin=4pt,
  innerrightmargin=4pt,
  innertopmargin=2pt,
  innerbottommargin=2pt,
  backgroundcolor=formalshade,
  topline=false,
  rightline=false,
  bottomline=false,
  linecolor=green,
  linewidth=2pt,
   ]{tipbox*}
\newenvironment{tipbox}[1][43]
  {\begin{tipbox*}
   \makebox[0pt][r]{\smash{\raisebox{-.333\height}{\Large\ding{#1}\hspace{10pt}}}}\ignorespaces}
  {\end{tipbox*}}

\begin{document}
\lipsum[1]

\begin{tipbox}
You can expect your organisation to perform better, but only if everyone is pointing in the same direction.

You can expect your organisation to perform better, but only if everyone is pointing in the same direction.
\end{tipbox}

\lipsum[2]
\end{document}

在此处输入图片描述

你可以得到一个黑手

\begin{tipbox}[42]

或使用您想要的任何符号的数字。

答案2

\llap命令是您的朋友。它将作为参数传递的内容排版到“左侧”,而不会改变插入位置。

\documentclass[a4paper,12pt]{article}
\usepackage{verbatim}
\usepackage{color}
\usepackage[english]{babel}
\usepackage{pifont}
\usepackage[strict]{changepage}
\usepackage{framed}
\usepackage{blindtext}

\definecolor{formalshade}{rgb}{0.95,0.95,1}

\newenvironment{tipbox}{%
  \def\FrameCommand{%
  {\llap{\Huge\ding{43}\hspace{1pt}}}
    %
    {\color{green}\vrule width 2pt}%
    {\color{formalshade}\vrule width 4pt}%
    \colorbox{formalshade}%
  }%
  \MakeFramed{\advance\hsize-\width\FrameRestore}%
  \noindent\hspace{-4.55pt}% disable indenting first paragraph
  \begin{adjustwidth}{}{7pt}%
  \vspace{2pt}\vspace{2pt}%
}
{%
  \vspace{2pt}\end{adjustwidth}\endMakeFramed%
}

\begin{document}

\blindtext

\begin{tipbox}
You can expect your organisation to perform better, but only if everyone pointing in the same direction.
\end{tipbox}

\blindtext

\end{document}

在此处输入图片描述

答案3

为了解决一个非常相似的问题,我使用了marginnote包。因此(使用书籍类)可以决定在左页和/或右页上显示的内容:\marginnote[left]{right}。使用包\scalebox中的命令graphicx可以镜像符号,这样就可以采用以下方法:

\documentclass[a4paper,12pt]{book}
\usepackage{verbatim}
\usepackage{color}
\usepackage[english]{babel}
\usepackage{pifont}
\usepackage[strict]{changepage}
\usepackage{framed}
\usepackage{blindtext}
\usepackage{marginnote}
\usepackage{graphicx}

\definecolor{formalshade}{rgb}{0.95,0.95,1}

\newenvironment{tipbox}{%
\def\FrameCommand{%
    \hspace{1pt}%
    {\color{green}\vrule width 2pt}%
    {\color{formalshade}\vrule width 4pt}%
    \colorbox{formalshade}%
  }%
  \MakeFramed{% 
  %
   \marginnote[\Huge\ding{43}]{\scalebox{-1}[1]{\Huge\ding{43}}}%
   %
   \advance\hsize-\width\FrameRestore}%
   \noindent\hspace{-4.55pt}% disable indenting first paragraph
   \begin{adjustwidth}{}{7pt}%
   \vspace{2pt}\vspace{2pt}%
}
{%
  \vspace{2pt}\end{adjustwidth}\endMakeFramed%
}

\begin{document}

\blindtext

\begin{tipbox}
You can expect your organisation to perform better, but only if everyone pointing in the same direction.
\end{tipbox}

\blindtext
\newpage
\begin{tipbox}
You can expect your organisation to perform better, but only if everyone pointing in the same direction.
\end{tipbox}
\end{document}

在此处输入图片描述

相关内容