计算最小页面宽度

计算最小页面宽度

我正在尝试使用 mini-page 将不同宽度的浮动元素居中。我希望定义中心页面的宽度并计算左右页面的宽度

我的计算正确,但 min-page 宏无法识别数字

\documentclass[a4paper,11pt]{article}
\usepackage{ifthen}

\newcommand{\mywidth}[1]{\ifthenelse{\equal{#1}{0.6}}{0.2}
                        {\ifthenelse{\equal{#1}{0.7}}{0.15}
                                {\ifthenelse{\equal{#1}{0.8}}{0.1}{0.1}}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\mypage}[2]{
    \begin{minipage}{\mywidth{#1}\textwidth}
    \end{minipage}
    \begin{minipage}{#1\textwidth}
        #2
    \end{minipage}
    \begin{minipage}{\mywidth{#1}\textwidth}
    \end{minipage}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

    \mywidth{0.6}

    \mywidth{0.7}

    \mywidth{0.8}

    \mypage{0.6}{Bye!}

\end{document}

答案1

\ifthenelse不能通过扩展来工作,并且minipage需要一个长度,即扩展到 tex 原始长度规范的东西。

另外,您的宏中有额外的空格,因此总宽度超过了文本宽度。

这更简单并且使用可扩展的计算。

\documentclass[a4paper,11pt]{article}
\usepackage{ifthen}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\mypage}[2]{%<<<<
    \begin{minipage}{\dimexpr(\textwidth-#1\textwidth)/2\relax}
    \end{minipage}%<<<<
    \begin{minipage}{#1\textwidth}
        #2
    \end{minipage}%<<<<
    \begin{minipage}{\dimexpr(\textwidth-#1\textwidth)/2\relax}
    \end{minipage}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}


    \mypage{0.6}{Bye!}

\end{document}

尽管不清楚为什么需要两边的两个空盒子。

相关内容