如何让小页面填充剩余宽度直至右边距?

如何让小页面填充剩余宽度直至右边距?

我正在尝试为家庭作业设计一个自定义的问题\解决方案环境(我知道这个exam课程,但我选择尝试自己制作)并且在对齐方面遇到了问题。

我已将 minipage 设置\linewidth为使用其宽度,但超出了右边距,如我的 MWE 中所示。有什么方法可以让它填充到右边距而无需设置特定长度?我可能会在以后更改文档边距,但我不想同时更改 minipage 的宽度。

另外,如您所见,问题距左边距很远,我希望它们离左边距更近一点。我该如何实现这一点?

\documentclass{article}

\usepackage{lipsum}
\usepackage{environ}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{thmtools}
\usepackage{array}
\usepackage{fancyhdr}
\RequirePackage[left=1in,right=1in,top=1.0in,bottom=1.0in]{geometry}

\makeatletter
\newcommand{\@coursenumber}{{\em No \textbackslash coursenumber specified}}
\newcommand{\@semester}{{\em No \textbackslash semester specified}}
\newcommand{\@studentname}{{\em \textbackslash studentname unknown}}
\newcommand{\@studentid}{{\em \textbackslash studentid unknown}}
\newcommand{\@school}{{\em \textbackslash school unknown}}
\newcommand{\@department}{{\em \textbackslash department unknown}}
\newcommand{\@lecture}{\textbackslash lecture}

\newcommand{\solutionstext}{\bfseries (Solutions)}
\newcommand{\coursenumber}[1]{\renewcommand{\@coursenumber}{#1}}
\newcommand{\semester}[1]{\renewcommand{\@semester}{#1}}
\newcommand{\studentname}[1]{\renewcommand{\@studentname}{#1}}
\newcommand{\studentid}[1]{\renewcommand{\@studentid}{#1}}
\newcommand{\school}[1]{\renewcommand{\@school}{#1}}
\newcommand{\department}[1]{\renewcommand{\@department}{#1}}
\newcommand{\lecture}[1]{\renewcommand{\@lecture}{#1}}

% These commands follow the titling package format for titles
% They define user commands to format the subtitle
\newcommand\presubtitle[1]{\gdef\@presubtitle{#1}}
\newcommand\postsubtitle[1]{\gdef\@postsubtitle{#1}}
% This command takes the subtitle as its argument, and uses the titling command
% \maketitlehookb plus the previously defined formatting commands to insert
% the subtitle into the titlepage. It also generates \thesubtitle for subsequent use
\newcommand\subtitle[1]{%
  \renewcommand{\maketitlehookb}{\@presubtitle#1\@postsubtitle}
  \newcommand\thesubtitle{#1}}
% Now we define the formatting for the subtitle
\presubtitle{\begin{center}\Large} % change this as needed
\postsubtitle{\end{center}}

% These commands set up the headers. They are set up for even and odd pages the same
% Check the fancyhdr documentation for information on how to set them differently
% for odd and even pages
\lhead{\begin{tabular}{@{}l}\@coursenumber\ (\@semester)\\\@studentname\ (\@studentid)\end{tabular}}
\chead{}
\rhead{\begin{tabular}{r@{}}Assignment \#\@lecture\\\today\end{tabular}}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
% Set the width of the header rule. Make 0pt to remove the rule.
\renewcommand{\headrulewidth}{.5pt}
\renewcommand{\footrulewidth}{0pt}
% Make the head height match the size of the header
\setlength{\headheight}{24pt}
\pagestyle{fancy}
\makeatother

\newcounter{problem}
\setcounter{problem}{0}
\newcounter{problempart}[problem]

\NewEnviron{problem}[1]{
  \stepcounter{problem}
  \begin{tabular}{m{3mm}l}
    \arabic{problem}. & \textbf{#1}\\[1mm]
    & \hfill
      \begin{minipage}{\linewidth}
        \BODY
      \end{minipage}
  \end{tabular}}

\let\proof\relax

\declaretheoremstyle[
    within=section,
    spaceabove=5mm,
    spacebelow=3mm,
    headfont=\bfseries,
    notefont=\normalfont,
    bodyfont=\itshape,
    headpunct=\newline,
    %postheadspace={10pt},
    notebraces={}{},
    headformat=\NAME:
]{proof}

\declaretheorem[style=proof,qed=\qedsymbol,name=Proof]{proof}
\declaretheorem[style=proof,qed=\qedsymbol,name=Solution]{solution}

\begin{document}
  \begin{problem}{Problem Title}
    \lipsum[1]
    \begin{solution}
      \lipsum[2]

    \end{solution}
  \end{problem}

  \begin{problem}{Problem 2}
    \lipsum[3]
  \end{problem}
\end{document}

答案1

使用

\NewEnviron{problem}[1]{%
  \stepcounter{problem}\noindent
  \begin{tabular}{m{3mm}p{\dimexpr\linewidth-3mm-3\tabcolsep\relax}@{}}
    \arabic{problem}. & \textbf{#1}\\[1mm]
    &       \BODY
  \end{tabular}}%

当你遇到两位数的问题时,你必须将长度改为3mm5mm在这种情况下,你可能会对以下内容感兴趣:

\newlength{\mylen}
\settowidth{\mylen}{100}

\NewEnviron{problem}[1]{%
  \stepcounter{problem}\noindent
  \begin{tabular}{m{\mylen}p{\dimexpr\linewidth-\mylen-3\tabcolsep\relax}@{}}
    \arabic{problem}. & \textbf{#1}\\[1mm]
    &       \BODY
  \end{tabular}}%

相关内容