我怎样才能将问号垂直置于这个类似定理的环境左侧?

我怎样才能将问号垂直置于这个类似定理的环境左侧?

如何修改以下环境以使问号垂直居中(其间距取决于文本长度)?

在此处输入图片描述

以下是生成该问题框的代码:

\documentclass[]{article} 
\usepackage{tikz}
\usepackage{environ}

\newtheorem{question}{Question}

\NewEnviron{myq}
{
    \noindent\fcolorbox{black}{gray!10}{
        \tikz\node[
        font=\fontfamily{ppl}\fontsize{1cm}{1.2cm}\selectfont]{?};
        \parbox{\textwidth}{
        \vspace*{-2mm}
        \begin{question}
                \BODY
        \end{question}
        }
    }
}

\begin{document}


\begin{myq}
  Here is some question in a gray box, 
  with a question mark to the left of it.     
  The thing is, I'd like the question mark to be 
  centered vertically within the box. How do I 
  do that?
\end{myq}

\end{document}

最初,我有一个问题,关于如何将文本放入框中以及如何将其变为灰色以及如何将大问号放在左侧,但我都弄明白了(在网上搜索后)。让问号垂直居中是我还没有弄明白的最后一部分。

答案1

试试这个代码。将标志插入?到 parbox 中,其宽度为标志的宽度,使用calc包计算。将两个 parbox 并排放置,总宽度为\linewidth

b

\documentclass[]{article} 
\usepackage{tikz}
\usepackage{environ}

\usepackage{showframe}% only to show the margins

\usepackage{calc}% added <<<<<<<<<<<
\newlength{\signwidth}  % added <<<<<<<<<<<
\setlength{\signwidth}{\widthof{\fontfamily{ppl}\fontsize{1cm}{1.2cm}\selectfont ?\ }}

\newtheorem{question}{Question}

\NewEnviron{myq}
{\noindent\fcolorbox{black}{gray!10}{%
        \parbox{\signwidth}{% added <<<<<<<<<
            \vspace*{-2mm}% OPTIONAL <<<<
            \tikz\node[font=\fontfamily{ppl}\fontsize{1cm}{1.2cm}\selectfont]{?};
        }
        \parbox{\dimexpr\linewidth-\signwidth-\marginparsep-2\fboxrule}{%changed <<<
            \vspace*{-2mm}
            \begin{question}
                \BODY
            \end{question}
        }
    }
}

\begin{document}
    
    
    \begin{myq}
        Here is some question in a gray box, 
        with a question mark to the left of it.     
        The thing is, I'd like the question mark to be 
        centered vertically within the box. How do I 
        do that?
    \end{myq}
    
\end{document}

相关内容