4

I just create a simple check list following the way described here: How do I generate a check-list?, My code is below:

\documentclass[a4paper,notitlepage]{article}
\usepackage[]{ctex}
\setCJKmainfont{SimSun}
\usepackage{graphicx}
\usepackage[twocolumn]{geometry}
\usepackage{amssymb}
\usepackage{array}
\newcounter{rowno}
\setcounter{rowno}{0}
\usepackage[export]{adjustbox}  % draw frame of the image
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm,headheight=1cm,headsep=1cm,footskip=1cm}


\usepackage{wasysym}     

\setlength{\marginparwidth}{1.2in}
\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\raggedleft #1]%
{\raggedright #1}}    

\newenvironment{checklist}{%
  \begin{list}{}{}% whatever you want the list to be
  \let\olditem\item
  \renewcommand\item{\olditem -- \marginpar{$\Box$} }
  \newcommand\checkeditem{\olditem -- \marginpar{$\CheckedBox$} }
}{%
  \end{list}
}   

\begin{document}
\begin{checklist}
  \checkeditem   Open the \TeX book
  \checkeditem   Find the good page
  \item   Try to understand
\end{checklist}
\end{document}

The question is, here I use twocolumn option, but you see the checkitem box was put on the left, why? Can you help me, thanks.

See the screen shot image below:

check box on left page

EDIT: This is the new code. I use the

\documentclass[a4paper,notitlepage]{article}
\usepackage{graphicx}
\usepackage[twocolumn]{geometry}
\usepackage{amssymb}
\usepackage{array}
\usepackage[export]{adjustbox}  % draw frame of the image
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm,headheight=1cm,headsep=1cm,footskip=1cm}

\usepackage{wasysym}

\setlength{\columnseprule}{0.4pt}
\setlength{\columnsep}{0.5in}

\newcommand\numitem[1]{\item #1 \hfill $\Box$}%
\newcommand\nonnumitem[1]{\item[--] #1 \hfill $\Box$}%


\begin{document}

\begin{enumerate}
  \numitem{Open the \TeX book Open the \TeX book Open the abc}
  \numitem{Find the good page}
  \nonnumitem{Try to understand}
\end{enumerate}

\newpage

\begin{enumerate}
  \numitem{Open the \TeX book Open the \TeX book Open the abcdefg}
  \numitem{Find the good page}
  \nonnumitem{Try to understand}
\end{enumerate}

\end{document} 

I found a bug that sometimes, the box was not put in the right side of the column, see the screen shot below: box shown on the left

So, any idea to fix this? Thanks.

EDIT2 I found some code snippet which can solve this issue(force the box go to the right side), just change the code to:

\newcommand\numitem[1]{\item #1 \unskip\linebreak[0]\enspace\hbox{}\nobreak\hfill$\Box$}%
\newcommand\nonnumitem[1]{\item[--] #1 \unskip\linebreak[0]\enspace\hbox{}\nobreak\hfill$\Box$}%

Then, I can fix this bug, but can any till me what does the code means? Thanks.

  • This is because, in twocolumn mode, the margin used to print the \marginpar is the left one when you are in the left column and the right one when you are in the right column. – karlkoeller Oct 16 '13 at 4:27
  • Thanks for the explanation, are there any way to fix this issue? – ollydbg23 Oct 16 '13 at 4:29
  • OK, I understand this issue now, there is a nice image showing that the margin position in the twocolumn mode, see: tex.stackexchange.com/questions/35833/…, but I still need a way to handle my original question. – ollydbg23 Oct 16 '13 at 4:56
7

The solution you're referring to doesn't work in two column mode, because the margin used to print the \marginpar is the left one when you are in the left column and the right one when you are in the right column.

This is a simple solution that doesn't use the margins to print the checkboxes, but it's far from perfect.

I've defined two new commands

\newcommand\noncheckeditem[1]{\item[--] #1 \hfill $\Box$}%
\newcommand\checkeditem[1]{\item[--] #1 \hfill $\CheckedBox$}%

to be used respectively when you want a non-checked and a checked item.

You can use them inside a normal description environment as follows:

\documentclass[a4paper,notitlepage]{article}
\usepackage{graphicx}
\usepackage[twocolumn]{geometry}
\usepackage{amssymb}
\usepackage{array}
\usepackage[export]{adjustbox}  % draw frame of the image
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm,headheight=1cm,headsep=1cm,footskip=1cm}

\usepackage{wasysym}

\setlength{\columnseprule}{0.4pt}
\setlength{\columnsep}{0.5in}

\newcommand\noncheckeditem[1]{\item[--] #1 \hfill $\Box$}%
\newcommand\checkeditem[1]{\item[--] #1 \hfill $\CheckedBox$}%

\begin{document}

\begin{description}
  \checkeditem{Open the \TeX book}
  \checkeditem{Find the good page}
  \noncheckeditem{Try to understand}
\end{description}

\newpage

\begin{description}
  \checkeditem{Open the \TeX book}
  \checkeditem{Find the good page}
  \noncheckeditem{Try to understand}
\end{description}

\end{document} 

Result:

enter image description here

Note that I've printed one on the left and one on the right column just to see how they look. For this purpose, I've also added the lines

\setlength{\columnseprule}{0.4pt}
\setlength{\columnsep}{0.5in}

Also note that the left and the right margin of your geometry are too small and you get warnings. You should put something like 3.5cm both for lmargin and rmargin.

  • Dear karkoeller, many thanks, your solution is really good. I will adjust the margin width, thanks for the help. – ollydbg23 Oct 16 '13 at 5:18
  • Hi Karlkoeller, sorry for bother again, I still see a bug in your code, sometimes, the box are still put in the left, I have show the code and screen shot in my updated original question, can you give a hand? Thanks. – ollydbg23 Oct 16 '13 at 7:05
  • The EDIT2 section in my original post fix this bug, but I don't why. – ollydbg23 Oct 16 '13 at 7:32
  • @ollydbg23 as I said, my answer was far from perfect. I'm happy that you've found a workaround for critical cases, but I'm not able to explain exactly what that code does. I can only tell you that it creates an empty horizontal box (\hbox{}) that keeps the \Box in the same line when there is enough space, otherwise puts it in the next line at end of it. – karlkoeller Oct 16 '13 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.