minipage 中的 \centering 无法使用

minipage 中的 \centering 无法使用

我正在创建一个通知环境,比如例子

代码为:

\documentclass{article}
\usepackage{tikz}
\usepackage[tikz]{bclogo,rotating}
\usetikzlibrary{calc}

\newenvironment{attention}
{\par\medskip\noindent
    \begin{tikzpicture}
    \node[inner sep = 0pt] (box) \bgroup%
    \begin{minipage}[t]{.48\textwidth}%
    \begin{minipage}{.25\textwidth}
%--------------------------------------------------------
    \raggedleft
%--------------------------------------------------------
    \tikz[scale = 1]\node[scale = 1, rotate = 0]{\bcattention};
    \end{minipage}%
    \begin{minipage}{.65\textwidth}
    \begin{center}}% former part
{%
    \end{center}
    \end{minipage}\hfill
    \end{minipage}%
    \egroup;
    \draw[black,line width=1.5pt]
    ( $ (box.north east) + (-20pt,3pt) $ ) -- ( $ (box.north east) + (-15pt,3pt) $ ) -- ( $ (box.south east) + (-15pt,-3pt) $ ) -- + (-5pt,0);
    \draw[black,line width=1.5pt]
    ( $ (box.north west) + (20pt,3pt) $ ) -- ( $ (box.north west) + (15pt,3pt) $ ) -- ( $ (box.south west) + (15pt,-3pt) $ ) -- + (5pt,0);
    \end{tikzpicture}}

\begin{document}
    \begin{attention}
        Lorem...
    \end{attention}
\end{document}

我想让感叹号图标在小页面中居中,所以我将宏改为%------------------------\centering但是没有用。然后我把 tikz 宏放入{center}环境中,但仍然没有用。之后,我尝试使用\centerline宏,但没有任何反应。

那么该怎么做呢?

答案1

稍微不同的方法(不知道,如果注意环境中的文本可以有更多行......因此假设符号是“注意”的最高元素):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[tikz]{bclogo,rotating}
\usetikzlibrary{calc}

\newsavebox{\att}
\newenvironment{attention}
    {\par\medskip\noindent
     \begin{lrbox}{\att}
    }% former part
    {\end{lrbox}
     \begin{tikzpicture}[node distance=0pt]
\node (n1) [minimum width=0.17\textwidth]{\bcattention};
\node (n2) [text width=0.21\textwidth,
            right=of n1]{\usebox{\att}};
%
\draw[line width=1.5pt]
    ([xshift= 2mm] n1.north west) -| (n1.south west) -- + ( 2mm,0)
    ([xshift=-2mm] n1.north -| n2.east) -| (n2.east |- n1.south) -- + (-2mm,0);
    \end{tikzpicture}
    }
\begin{document}

    \begin{attention}
        Lorem...
    \end{attention}
\end{document}

在此处输入图片描述

附录: 如果文本attention有多行,则需要采用上述解决方案来满足这一需求:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[tikz]{bclogo,rotating}
\usetikzlibrary{calc}

\newsavebox{\att}
\newenvironment{attention}
    {\par\medskip\noindent
     \begin{lrbox}{\att}
    \begin{minipage}{0.22\textwidth}% added
    }% former part
    {\end{minipage}% added
     \end{lrbox}
     \begin{tikzpicture}[node distance=0pt,
every node/.style = {minimum width=0.17\textwidth, minimum height=11mm}% added
                        ]
\node (n1)                  {\bcattention};  % changed
\node (n2) [right=of n1]    {\usebox{\att}}; % changed
%
\draw[line width=1.5pt]
    ([xshift= 2mm] n1.west |- n2.north) -| (n1.west |- n2.south) -- + ( 2mm,0)
    ([xshift=-2mm] n2.north east) -| (n2.south east) -- + (-2mm,0);
    \end{tikzpicture}
    }
\begin{document}
    \begin{attention}
        Lorem ipsum ...
    \end{attention}
    \begin{attention}
        Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    \end{attention}
\end{document}

在此处输入图片描述

相关内容