2

Sometimes I wish to use the \input{...} command when writing papers. However, in TeXstudio, my editor of choice, this messes up the Structure Tree display on the left-hand side. While I realise some people don't use this, I find it very helpful for quickly navigating---additionally, right-click on a section and it gives the option to add the \ref{sec:...}, which is helpful.

I include here an example. It doesn't compile since it needs an auxiliary file, but if it is pasted into TeXstudio, the issue is apparent. I have also included a picture showing what happens. In short, the \input{...} part is put on the highest tree-level. Is this a known bug with a known fix?

Related: Using structural commands in \newcommand - structure messed up?

\documentclass[]{article}
\begin{document}
\section{Section 1}
\subsection{Subsection 1.1}
\input{some_code.tex}
\subsection{Subsection 1.2}
\section{Section 2}
\subsection{Subsection 2.1}
\subsection{Subsection 2.2}
\end{document}

enter image description here

Sam OT
  • 1,329
  • Oh you mean the following subsection 1.2. Make a bug report in the texstudio issue tracker. – Ulrike Fischer Apr 14 '20 at 13:31
  • I actually found a solution via the related questions. (Often it's easier to find stuff on Stack Exchange via the "related questions" than searching directly!) I have copied this answer below (giving credit to the original poster). – Sam OT Apr 14 '20 at 13:42

1 Answers1

2

Since posting this, I have found the solution on another tex.SE question: TexStudio Structure Overview gets broken by a figure. While the question there is phrased in terms of being broken by a figure, it appears that the underlying issue is the \input{...} rather than the figure. It is perhaps for this reason that I did not come across the linked question in my research; hence I have kept this question open, in the hope that it will be easier for people in the future!

To be self-contained, and for preservation should anything happen to the linked answer, I have directly copied the answer here, due to user Corbie. I claim no originality for what is below.


  1. Go to Options -> Configure TeXstudio...,
  2. check Show Advanced Options in the bottom left corner,
  3. go to Adv. Editor,
  4. under Structure Panel check Keep indentation of includes in structure tree.

Check this box in the settings


Note: you may have to restart TeXstudio for this to take affect

Sam OT
  • 1,329
  • Thanks, this works! For me the problem occured for a table that I imported using the \input command. I kept the table in a separate file since it was generated by pandas (the Python library). – hexcoffee Mar 13 '23 at 12:15
  • @hexcoffee Glad it helped you! – Sam OT Mar 13 '23 at 15:41