如何將問號垂直居中在這個類似定理的環境的左邊?

如何將問號垂直居中在這個類似定理的環境的左邊?

如何修改以下環境以使問號垂直居中顯示(其間距取決於文字長度)?

在此輸入影像描述

這是產生該問題框的程式碼:

\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

試試這個程式碼。將標誌插入?到具有標誌寬度(使用calc套件計算)的 parbox 中。將兩個 parbox 並排放置,總寬度為\linewidth

乙

\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}

相關內容