TransWikia.com

How to unfold rows in a table

TeX - LaTeX Asked by Martund on May 3, 2021

I am trying to unfold rows in a table, just like text can be created to be shown and hidden using ocgx package. The problem here is that if I enter that line (of creating corresponding row in table) in ocgx, it shows error (obviously, since the full tabular environment is not in the ocg environment, just the line with alignment characters).

I want an environment that can compile or not compile the code written in it at my wish (toggled by pressing a button). Is that possible?

MWE

documentclass{article}
usepackage{ocgx}
begin{document}
    begin{tabular}{|c|c|} hline
            Hi&Hello hline   
            begin{ocg}{OCG 1}{ocg1}{1}
                Hi&hello     hline
             end{ocg}
    end{tabular}
    
    switchocg{ocg1}{Button.}
end{document}

EDIT Another MWE based on answer of AlexG.

usepackage{ocgx2} 
usepackage{hyperref} 

begin{document} 
    noindent% 
    begin{tabular}{|c|c|} hline 
        This is &row 1 hline   
    end{tabular}[-dimexprlineskip+fboxrulerelax] 
    begin{ocg}{OCG 1}{ocg1}{on} 
        begin{tabular}{|c|c|}hline 
            This is &row 2 hline 
        end{tabular}[-dimexprlineskip+fboxrulerelax]
    end{ocg}
    begin{tabular}{|c|c|} hline 
        This is &row 3 hline   
    end{tabular}
    noindentswitchocg{ocg1}{Button.} 
end{document}

Note that on pressing the button, second row becomes invisible, but it is still there, that I don’t want. It should be replaced by row 3 on pressing the button.

One Answer

Alignment characters of tabular may not be used within any user-defined environment. (You may verify this with a no-op environment, such as newenvironment{bla}{}{}).

One way to work around this could be wrapping every table row within a tabular of its own:

documentclass{article} 
usepackage{ocgx2} 
usepackage{hyperref} 
 
newenvironment{blabla}{}{} 
 
begin{document} 
    noindent% 
    begin{tabular}{|c|c|} hline 
            Hi&Hello hline   
    end{tabular}[-dimexprlineskip+fboxrulerelax] 
    begin{ocg}{OCG 1}{ocg1}{on} 
      begin{tabular}{|c|c|}hline 
              Hi&Hello hline 
      end{tabular} 
    end{ocg} 
 
    noindentswitchocg{ocg1}{Button.} 
end{document}

"Unfolding" is not possible with the PDF format. In contrast to HTML, PDF is paginated content. After typesetting the stream of input, every glyph has its fixed position within a paragraph of text and within a page.

"Unfolding", as requested, would require re-typesetting the whole document during viewing time whenever text is hidden or shown by user-interaction, because the arrangement of paragraphs, the number of pages and even the table of contents would change. But, PDF viewers do not have a built-in (LaTeX-)typesetter.

Correct answer by AlexG on May 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP