1

I'm trying to do the usual "make a worksheet with blank spaces", and I need blanks longer than the text which will eventually fill them (so that students can write in answers by hand). Unfortunately, my command "blank" prints a strange amount of space before evaluating in the text. If I just insert the same command in the body, it evaluates normally.

    \documentclass[]{article}
    \newlength\mylen
    \newlength\fieldlen
    \newcommand\blank[1]{%
       \settowidth\mylen{#1}
       \settowidth\fieldlen{0}
       \addtolength\fieldlen{\mylen}
       \addtolength\fieldlen{\mylen}
       \underline{\makebox[\fieldlen]{}}    %comment this line and uncomment next line to hide answers
       %\underline{\makebox[\fieldlen]{#1}} %comment this line and uncomment previous line to show answers
    }
    \begin{document}

Using the macro, I get the following:

We find that $G<$\blank{$G_1$}.

There's an extra space before the underline. 

I want it to look like:

We find that $G<$\underline{\makebox[\fieldlen]{}}.
\end{document}
1

1 Answer 1

1

The usage of the macros \settowidth and \addtolength is missing a % at the end, so 4 missing % will lead to one additional space character each.

As well there is a missing % after \underline, so the . is shifted to the right.

  \documentclass[]{article}
  \newlength\mylen
  \newlength\fieldlen
  \newcommand\blank[1]{%
    \settowidth{\mylen}{#1}%
    \settowidth{\fieldlen}{0}%
    \addtolength{\fieldlen}{\mylen}%
    \addtolength{\fieldlen}{\mylen}%
    \underline{\makebox[\fieldlen]{}}%    %comment this line and uncomment next line to hide answers
    % \underline{\makebox[\fieldlen]{#1}} %comment this line and uncomment previous line to show answers
  }
  \begin{document}

Using the macro, I get the following:

We find that $G<$\blank{$G_1$}.

There's an extra space before the underline. 

I want it to look like:

We find that $G<$\underline{\makebox[\fieldlen]{}}.
\end{document}

enter image description here

6
  • Thanks! By the way, how do you get the Latex to print in the post like that?
    – richbenp
    Mar 15, 2018 at 18:04
  • @richbenp: Make a screenshot of the output in your PDF viewer and save it as .jpg or .png file. There is no way to cause TeX.SE to compile and display the output
    – user31729
    Mar 15, 2018 at 18:06
  • @ChristianHupfer: $G<{}$ would look better, I think.
    – Bernard
    Mar 15, 2018 at 19:01
  • @Bernard: That was not the issue, however
    – user31729
    Mar 15, 2018 at 19:02
  • I will happily accept the answer ... although I confess ignorance about how to do so!
    – richbenp
    Mar 15, 2018 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .