This is perfect! and very illustrative, new LaTex tricks to learn :)
Thanks Benjamin!



El mié., 27 may. 2020 a las 8:57, Benjamin Berg (<[email protected]>)
escribió:

> Hi,
>
> I think the below does the trick. I restructured your question layout a
> bit, assuming that only one of the Dxx checkboxes may be selected.
>
> The idea is to pre-define the answers but only place them later on. The
> time of placement does not matter and this means that the global state
> used for numbering, etc. is always consistent.
>
> See attached document for the proof that it works (i.e. the output of
> "sdaps annotate"). It doesn't show the assigned variable names though.
>
> Benjamin
>
>     \ExplSyntaxOn
>     \let\qbegin\sdaps_qobject_begin:nnn
>     \let\qend\sdaps_qobject_end:n
>     \newcommand{\idprefix}[2]{
>     #1
>     \sdaps_answer:n { idprefix} \sdaps_checkbox:nn {} {#2}
>     }
>
>     \newcommand{\iddigits}[1]{
>       \sdaps_qobject_begin:nnn {iddigits}{Option}{iddigits~#1}
>       \sdaps_checkbox_set_type:n {singlechoice}
>
>       \int_step_inline:nnnn { 0 } { 1 } { 9 } {\sdaps_answer:n { 1_##1}
> \sdaps_checkbox:nn{2_##1}{} & }
>       \sdaps_qobject_end:n {iddigits}
>     }
>
>     \newcommand{\idheader}{
>         & \int_step_inline:nnnn { 0 } { 1 } { 9 } { ##1 & }
>         & \int_step_inline:nnnn { 0 } { 1 } { 9 } { ##1 & }
>         & \int_step_inline:nnnn { 0 } { 1 } { 9 } { ##1 & } \\
>     }
>     \ExplSyntaxOff
>
>     %\question{Person-ID}
>     % Setup is as follows:
>     % - One Header/Section to group all of these questions,
>     %   this mostly affects numbering but is also used later.
>     % - One Option question for the first column (idprefix). The checkboxes
>     %   are pre-defined and stored into LaTeX boxes. The question is then
>     %   ended before the boxes are placed into the document.
>     % - Change the variable to get an iddigits prefix for all remaining
>     %   questions in this section/group/context.
>     % - Place the pre-defined boxes and define the other questions
> in-place.
>     %   Note that the pre-defined boxes must only be used exactly once.
>     \qbegin{sid}{Head}{Subject ID}
>       \qbegin{idprefix}{Option}{idprefix}
>         \ExplSyntaxOn
>         \sdaps_qobject_append_var:n {idprefix}
>         \sdaps_checkbox_set_type:n {singlechoice}
>         \ExplSyntaxOff
>         \newbox\boxda \newbox\boxdb \newbox\boxdc \newbox\boxdd
> \newbox\boxde
>         \savebox\boxda{\mbox{\idprefix{D10 }{10}}}
>         \savebox\boxdb{\mbox{\idprefix{D20 }{20}}}
>         \savebox\boxdc{\mbox{\idprefix{D21 }{21}}}
>         \savebox\boxdd{\mbox{\idprefix{D22 }{22}}}
>         \savebox\boxde{\mbox{\idprefix{D40 }{40}}}
>       \qend{idprefix}
>
>       \ExplSyntaxOn
>       \sdaps_qobject_append_var:n {iddigits}
>       \ExplSyntaxOff
>       \setlength{\tabcolsep}{2pt}
>       \begin{tabular}{l |c|ccccccccc c cccccccccc c cccccccccc c}
>           \idheader
>           \unhbox\boxda &\iddigits{1} & \iddigits{2} & \iddigits{3}\\
>           \unhbox\boxdb \\
>           \unhbox\boxdc \\
>           \unhbox\boxdd \\
>           \unhbox\boxde
>       \end{tabular}
>     \qend{sid}
>
>
> On Tue, 2020-05-26 at 17:41 +0200, Benjamin Berg wrote:
> > On Tue, 2020-05-26 at 14:51 +0200, Santiago Timón wrote:
> > > I'm trying to use a custom layout, placing checkboxes in a bunch of
> > > columns to have an ID mechanism. But I'm having this result:
> > >
> > > What could be the cause? (column lines used to inspect the
> > > alignment)
> > >
> > > As you know, I'm not very proficient with LaTex and you'll probably
> > > find this code quite nasty...
> >
> > Well … it is LaTeX, it doesn't tend to be very nice.
> >
> > Anyway, the problem is with your table definition. You are making
> > every
> > column 1pt wide, which is not even wide enough to fit the heading.
> > And
> > that then makes things left aligned in effect.
> >
> > You should do something like:
> >
> >         \setlength{\tabcolsep}{2pt}
> >         \begin{tabular}{l |c|ccccccccc c cccccccccc c cccccccccc c}
> >
> > And I don't think you need the "\int_compare:nT { ##1 < 9 } { ~ }"
> > everywhere, not sure why you are inserting spaces there.
> >
> >
> > There is a problem though. Your code generates questions that are
> > nested, and it seems that the metadata ends up not being readable.
> > i.e.
> > the "idprefix" question wraps the other questions.
> >
> > I don't have a good idea right now how to work around that.
> >
> > Btw. if you can, I would really suggest sticking a barcode into a
> > field
> > instead.
> >
> > Benjamin
> >
> > > \ExplSyntaxOn
> > >     \newcommand{\idprefix}[2]{
> > >     \sdaps_qobject_begin:nnn {  } { Option } {idprefix}
> > >     \sdaps_qobject_append_var:n {idprefix}
> > >     \sdaps_checkbox_set_type:n {singlechoice}
> > >     #1
> > >     \sdaps_answer:n { idprefix} \sdaps_checkbox:nn {} {#2}
> > >     \sdaps_qobject_end:n {}
> > >     }
> > >
> > >     \newcommand{\iddigits}[1]{
> > >     \sdaps_qobject_begin:nnn {iddigits}{Option}{iddigits_#1}
> > >     \sdaps_qobject_append_var:n {iddigits_#1}
> > >     \sdaps_checkbox_set_type:n {singlechoice}
> > >
> > >         \int_step_inline:nnnn { 0 } { 1 } { 9 } {\sdaps_answer:n {
> > > 1_##1} \sdaps_checkbox:nn{2_##1}{} &  \int_compare:nT { ##1 < 9 } {
> > > ~
> > > } }
> > >
> > >     \sdaps_qobject_end:n {iddigits}
> > >     }
> > >
> > >     \newcommand{\idheader}{
> > >         & \int_step_inline:nnnn { 0 } { 1 } { 9 } { ##1 &
> > > \int_compare:nT { ##1 < 9 } { ~ }}
> > >         & \int_step_inline:nnnn { 0 } { 1 } { 9 } { ##1 &
> > > \int_compare:nT { ##1 < 9 } { ~ }}
> > >         & \int_step_inline:nnnn { 0 } { 1 } { 9 } { ##1 &
> > > \int_compare:nT { ##1 < 9 } { ~ }} \\
> > >     }
> > >     \ExplSyntaxOff
> > >
> > >     \question{Person-ID}
> > >     \qbegin{sid}{Option}{Subject ID}
> > >         \begin{tabular}{l
> > > > m{1pt}|m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt} c
> > > m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt} c
> > > m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt}m{1pt} c}
> > >             \idheader
> > >             \idprefix{D10 }{10} &\iddigits{1} & \iddigits{2} &
> > > \iddigits{3}\\
> > >             \idprefix{D20 }{20} \\
> > >             \idprefix{D21 }{21} \\
> > >             \idprefix{D30 }{30} \\
> > >             \idprefix{D40 }{40}
> > >         \end{tabular}
> > >     \qend{sid}
> > >
> > > Is there anything I'm missing?
> > > Thanks!
> > > --
> > > Santi
>


-- 
Santi

Reply via email to