1

I am wondering if I can write a rule for this? Is a rule even a good idea for this or is it better if I keep doing the table. Happy to hear any thoughts.

Also trying to create that red arrow and the label of x10 over it but not really sure how to do this.

I am happy to just keep doing the table if better.

Thank you

enter image description here

Warning- very messy...

\documentclass[
  a5paper,
  % pagesize,11pt,% both are default and therefore not needed
  bibliography=totoc,% bibtotoc is deprecated and therefore replaced according
                     % to the warning message
  numbers=noenddot,% pointlessnumbers is deprecated and therefore replaced
                   % according to the warning message
  headings=normal,% normalheadings is deprecated and therefore replaced
                  % according to the warning message
  DIV=9,twoside=false,
  headsepline,footsepline,footinclude=false,% see the KOMA-Script manual
headheight=87pt,% not used, to not lower the header, but this results in a warning
footheight=52pt, % no longer needed, because the lines are not part of the footer
]{scrbook}

\KOMAoptions{DIV=last}

\usepackage{trajan}

\usepackage{setspace}

\linespread{1.05}

\KOMAoptions{DIV=last}% moved according to the KOMA-Script manual, because it % makes no sense before changing font an linespread.

\usepackage{graphicx}

\usepackage[% autoenlargeheadfoot=false,% only warn but don't change height reserved for header or footer
manualmark,% or maybe automark, this is not clear due to missing information % in the question. plainheadsepline,plainfootsepline,% See the KOMA-Script manual for more information ]{scrlayer-scrpage}

\usepackage{geometry} \geometry{ a5paper, total={100mm,200mm}, %not sue what this line is either. left=15mm, right=15mm, top=30mm, bottom=35mm, headsep=2mm, }

\usepackage[dvipsnames]{xcolor}

\definecolor{ssblue}{rgb}{0.22,0.714,1} \definecolor{red}{RGB}{214,39,41} \definecolor{Lgreen}{RGB}{125,173,62} \definecolor{Dgreen}{RGB}{74,108,47} \definecolor{O}{RGB}{252,133,0}

\usepackage[framemethod=tikz]{mdframed} \usepackage{lipsum} \usetikzlibrary{shadows} \newmdenv[tikzsetting={fill=white}, roundcorner=0pt,shadow=false,]{myshadowbox}

%%%Highlightbox \usepackage[framemethod=tikz]{mdframed} \usepackage{lipsum} \usetikzlibrary{shadows} \newmdenv[tikzsetting={fill=ssblue!50}, roundcorner=0pt,shadow=false,]{highlight}

\newtheorem{example}{Example} \let\oldexample\example \renewcommand{\example}{\oldexample\normalfont}

%%%%%%%%%%%%%%%%%Packagaes%%%%%%%%%%%%%%%%%%%%%% \usepackage{amsmath}

\usepackage{enumitem}

\usepackage{tikz}

\usepackage{multicol,amsmath,amsfonts} \usepackage{enumitem} \usepackage{tasks}

\usepackage{cancel}

%%%%%%%%%table \usepackage{pbox} \usepackage{tabularray} \UseTblrLibrary{booktabs} \usepackage{xcolor,colortbl} %%%%%%%%%table

\begin{document}

\begin{enumerate}[labelwidth=1.5em, labelsep=0.5em, wide=0pt]\everymath{\displaystyle} \item Fill in the blanks. \begin{tasks}label=\alph*), label-width=1.5em, after-item-skip=10pt \task Multiply 0.3 by 10.

            \begin{tblr}{colspec = {|X[2,c]|X[0.1,c]|X[2,c]|X[2.3,c]| X[2.4,c]|},
        column{2} = {gray!40},
        cell{1}{1} = {ssblue!40},
        cell{1}{3} = {red!40},
        cell{1}{4} = {yellow!40},
        cell{1}{5} = {Lgreen!40},}
            \hline
             \textbf{Ones} &  & \textbf{Tenths} & \textbf{Hundredths} & \textbf{Thousandths} \\
            \hline
            & $\cdot$ & 3\\
            \hline
            3 & $\cdot$& \\
            \hline
            \end{tblr}

            \begin{align*}
                \text{3 tenths} \times 10 &= \rule{2cm}{0.1mm} \; \text{tenths} \\
                &= \rule{2cm}{0.1mm} \; \text{ones} \\
            \end{align*}
            So, $0.3 \times 10$ = \rule{2cm}{0.1mm}
    \end{tasks}

\end{enumerate}

\end{document}

  • Please minimise your code. We do not need a long preamble if your question is about a table. Also, can you link to your previous question(s) in case they are relevant? I notice somebody has gone to a good deal of trouble to update and comment your preamble, but you don't seem to have gone through them. Are you aware that setting up a page layout with koma and then loading geometry means you are basically undoing that layout and very possibly breaking other koma-ish things? – cfr Mar 31 '24 at 02:45
  • Also, can you explain what you mean by a 'rule'? What do you want it to do exactly? Do you always want the same columns and colours, for example? Are there always two rows to fill in? – cfr Mar 31 '24 at 02:56
  • @cfr, I fixed an issue that I was having (narrow margins) the only way I knew how. Thank you for letting me know. I will do more research. – user292225 Mar 31 '24 at 03:25
  • https://tex.stackexchange.com/a/258777/292225

    Something like this, so that I don't have to write everything with the table and just write the numbers. No worries if too much work. Thank you

    – user292225 Mar 31 '24 at 03:28
  • I imagine DIV=9 has something to do with that. – cfr Mar 31 '24 at 03:32
  • OK. I figured you wanted a command or environment ;). But what stays the same and what changes? – cfr Mar 31 '24 at 03:33
  • 1
    You probably shouldn't redefine red. I think it is on the LaTeX list of colours-you-shouldn't-redefine, but I haven't checked. – cfr Mar 31 '24 at 03:39
  • The table stays the same but the numbers in cells change. The arrows would change as well. Arrows could also go from thousandths to ones or something like that. Hard. And good point, thank you. I will make it myred then. It's not the same as the usual red in LaTeX. – user292225 Mar 31 '24 at 03:44
  • I forgot the arrow, but I think it should be a different question as it's not really part of automating the table per se. One way would be to use a tikzpicture, but then I'd be inclined to just use a matrix of nodes rather than messing about with tabularray. But that's not really an answer to how to automate this. (Actually, automating a tikzpicture would be more straightforward in a way as you don't have to worry about tabularray's parser. Though PGF has its own, too ....) – cfr Mar 31 '24 at 04:57
  • Actually, I guess you can just you tikzmark in the values list and it seems to work. I'd still be inclined to switch to TikZ but maybe not at this point. – cfr Mar 31 '24 at 05:18

1 Answers1

1

Something like this? You could automate the task as a whole, probably, if they are similar enough, but I don't know how much variation there is so I've only tried to handle the table.

\tsktens[<key-value list>]{<comma-separated list>} takes an optional and a mandatory argument.

  • If specified, the optional argument may be used to change the colours of the column headers for a particular table. The colours are specified as colones={<colour>},coltenths={<colour>} and so on, with coldot=<colour> for the dot column.
  • The mandatory argument is a list of entries for the cells of the table from top left to top right and then bottom left to bottom right, with no entry for the second column. Empty cells are specified by empty entries, except these may be omitted if all further values are to be empty. For example, \tsktens{1,2,3,4,5,6,7,8} would create a row for 1.234 above a row for 5.678, while \tsktens{,,1,3} would create a row for __13 above an entirely empty row.
    • To name the contents of cells in order to draw arrows between them, enter the cell value in the form <content>|<name>. <name> should be both unique and simple. (Letters and numbers should be OK. At least some punctuation is not e.g. n.3 doesn't work but a is OK.) For example, ,,3|a,,,3|b will name the node in the first row a and that in the second b. These may then be used in tikzpictures to draw the arrows as shown below.
    • Theoretically, the arrows could be automated, too, but I doubt this makes sense. The labels over the arrows need to be placed in different places to ensure readability. Of course, you can create arguments and key-value interfaces etc., but I doubt the effort would be worth it given that (1) the names need to be unique, (2) the number of arrows may differ, (3) the position and content of labels needs to vary and (4) the colour is probably best varied, too, in case of multiple arrows. However, if you're doing something more restricted, you could always create some form of shortcut.
      • Note that the use of tikzmark to enable arrows with a tabularray environment means at least two compilations are required. If the basic table was created as a matrix of nodes this would be avoidable.
      • If you externalise images, you may need to disable externalisation (external library) or find it is automatically disabled (memoize), depending on the method you use.

If it were not for the use of tabularray, this could be done more concisely, but tabularray needs to parse the rows and columns before typesetting so we can't automate it in ways which would hide the structure from the parser. (Standard tabular etc. don't do this, but they don't have the bells and whistles of tabularray, I guess.)

\documentclass{article}
% ateb: https://tex.stackexchange.com/a/714449/ addaswyd o gwestiwn user292225: https://tex.stackexchange.com/q/714446/
\usepackage{tabularray}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{tikzmark,arrows.meta}
\usepackage{enumitem}
\usepackage{tasks}
\definecolor{ssblue}{rgb}{0.22,0.714,1}
\definecolor{myred}{RGB}{214,39,41}
\definecolor{Lgreen}{RGB}{125,173,62}
\newlist{tenumerate}{enumerate}{1}
\setlist[tenumerate]{label=\arabic*.,labelwidth=1.5em,labelsep=0.5em,wide=0pt,before={\everymath{\displaystyle}}}
\ExplSyntaxOn
\seq_new:N \l__tsktens_cells_seq
\seq_new:N \l__tsktens_tmpa_seq
\keys_define:nn { tsktens }
{
  colones .code:n = {\colorlet{colones}{#1}},
  colones .initial:n = {ssblue!40},
  coltenths .code:n = {\colorlet{coltenths}{#1}},
  coltenths .initial:n = {myred!40},
  colhundredths .code:n = {\colorlet{colhundredths}{#1}},
  colhundredths .initial:n = {yellow!40},
  colthousandths .code:n = {\colorlet{colthousandths}{#1}},
  colthousandths .initial:n = {Lgreen!40},
  coldot .code:n = {\colorlet{coldot}{#1}},
  coldot .initial:n = {gray!40},
}
\NewDocumentCommand \tsktens { o m }
{
  \group_begin:
    \IfValueT { #1 }
    {
      \keys_set:nn { tsktens } { #1 }
    }
    \seq_set_split:Nnn \l__tsktens_cells_seq {,} { #2 }
    \seq_map_indexed_inline:Nn \l__tsktens_cells_seq
    {
      \seq_set_split:Nnn \l__tsktens_tmpa_seq { | } { ##2 }
      \int_compare:nNnT { \seq_count:N \l__tsktens_tmpa_seq } = { 2 }
      {
        \exp_args:NNNe \seq_set_item:Nnn \l__tsktens_cells_seq { ##1 } 
        {
          \exp_not:N \tikzmarknode { \seq_item:Nn \l__tsktens_tmpa_seq { 2 } } 
          { \seq_item:Nn \l__tsktens_tmpa_seq { 1 } }
        }
      }
    }
    \begin{tblr}{colspec = {|X[2,c]|X[0.1,c]|X[2,c]|X[2.3,c]| X[2.4,c]|},
        column{2} = {coldot},
        cell{1}{1} = {colones},
        cell{1}{3} = {coltenths},
        cell{1}{4} = {colhundredths},
        cell{1}{5} = {colthousandths},}
      \hline
      \textbf{Ones} &  & \textbf{Tenths} & \textbf{Hundredths} & \textbf{Thousandths} \\
      \hline
      \seq_item:Nn \l__tsktens_cells_seq {1} & $\cdot$ & \seq_item:Nn \l__tsktens_cells_seq {2} & \seq_item:Nn \l__tsktens_cells_seq {3} & \seq_item:Nn \l__tsktens_cells_seq {4} \\
      \hline
      \seq_item:Nn \l__tsktens_cells_seq {5} & $\cdot$ & \seq_item:Nn \l__tsktens_cells_seq {6} & \seq_item:Nn \l__tsktens_cells_seq {7} & \seq_item:Nn \l__tsktens_cells_seq {8} \\
      \hline
    \end{tblr}
  \group_end:
}
\ExplSyntaxOff
\tikzset{%
  >/.tip=Latex,
}
\begin{document}
\begin{tenumerate}
  \item Fill in the blanks.
  \begin{tasks}[label=\alph*), label-width=1.5em, after-item-skip=10pt](1)
    \task Multiply 0.3 by 10.
\tsktens {,3|a,,,3|b}
\begin{tikzpicture}[remember picture,overlay]
  \draw [myred,-&gt;] (a) -- node [pos=.75,above,sloped,myred] {$\times 10$} (b);
\end{tikzpicture}

\begin{align*}
  \text{3 tenths} \times 10 &amp;= \rule{2cm}{0.1mm} \; \text{tenths} \\
  &amp;= \rule{2cm}{0.1mm} \; \text{ones} \\
\end{align*}
So, $0.3 \times 10$ = \rule{2cm}{0.1mm}
\task Multiply 0.042 by 100.

\tsktens [colhundredths=magenta!40] {,,4|c,2|d,4|e,2|f}
\begin{tikzpicture}[remember picture,overlay]
  \draw [ssblue,-&gt;] (c) -- node [pos=.5,above,sloped,ssblue] {$\times 100$} (e);
  \draw [myred,-&gt;] (d) -- node [pos=.65,below,sloped,myred] {$\times 100$} (f);
\end{tikzpicture}

\end{tasks} \end{tenumerate} \end{document}

enter image description here

egreg
  • 1,121,712
cfr
  • 198,882
  • Hi. I made sure to read everything- with limited understanding. Thank you. I am trying to use it and there is an issue with the arrows which are not appearing and the numbers are in the wrong place. I thought it may be my page size, margins... something incompatible but I even just tried to copy this exactly into a new document and seems to have the same issue with even more errors.

    Also, Is it possible to add arrows if I use my own table? Seems that the arrows are a tikz things and I am starting with tblr...

    Again, Many thanks.

    – user292225 Mar 31 '24 at 10:16
  • @user292225 You need to compile twice for the arrows to show up in the correct places. Did you do that? The first time they will either be wrongly placed or they may not show up at all. If you change stuff so the positioning changes on the page, you have to compile twice again. – cfr Mar 31 '24 at 15:27
  • @user292225 You can say \tikzmarknode{<name>}{<content>} for <content> in your own table (or somewhere else) and then add the tikzpicture in the same way. – cfr Mar 31 '24 at 15:32