2

I would like to obtain the following result:

enter image description here

I am workint with Overleaf and stuck in the following MWE:

\documentclass{article}
\usepackage{chemfig}
\begin{document}
\chemfig{
-[:+30]  % C1
-[::-60] % C2
(-[::-60] -[::+45] NH_2)
-[::+45, 3]
}
\end{document}

I think that Overleaf doesn't load the latest version of chemfig package, since I tried to code the brackets with no success (and then I don't display the corresponding piece of code in the MWE). Is it possible to get the brackets by any other means? What about the *HCl floating above the NH2?

Brasil
  • 1,286

1 Answers1

2

Modified Answer:

So the request is to not use \polymerdelim. I have come up with a solution thanks to Heiko Oberdiek and this. The approach is to use a TikZ matrix that will have only one cell (which will be the chemfig). The square brackets needed to be shifted inside which made the positioning of the subscript n to be manually adjusted.

Output

\documentclass{article}
\usepackage{chemfig, tikz}
\usetikzlibrary{matrix}

\newsavebox\ourFormula
\sbox\ourFormula{
\chemfig[atom sep = 1.5em]{
    -[@{opening,0.75}:30]                       % Left opening bracket
    -[:+30]                                     % C1
    -[::-60]                                    % C2
    (
      -[::-60] -[::+45] NH_2                    % NH_2
     \raisebox{2em}{\hspace{-2em}$\bullet$ HCI} % HCI
    )
    -[::+45, 3] 
    -[@{closing,0.25}:+15]                      % Right closing bracket
  }
}
\begin{document}
  \begin{tikzpicture}[
    every left delimiter/.style={xshift=20pt},
    every right delimiter/.style={xshift=-20pt}
  ]
    \node (matrix) [left delimiter = {[}, right delimiter = {]}] {
      \usebox\ourFormula\\
    };
    \node [ xshift=48pt, yshift=-25pt] {$n$};
  \end{tikzpicture}
\end{document}

Original Answer: The brackets can be easily obtained using the \polymerdelim marco (it also takes care of the right subscript n). Now, the challenge is to have the •HCI above NH_2. The way I did it is by using \raisebox{vertical distance}{text}. This made the •HCI to be positioned top right with respect to NH_2. The solution is to use \hspace{negative distance} to pull it over to the left and have them vertically aligned.

In the case you wanted to change the code, make sure to compile it twice.

Output

\documentclass{article}
\usepackage{chemfig}
\begin{document}
  \chemfig[atom sep = 1.5em]{
    -[@{opening,0.75}:30]                       % Left opening bracket
    -[:+30]                                     % C1
    -[::-60]                                    % C2
    (
      -[::-60] -[::+45] NH_2                    % NH_2
     \raisebox{2em}{\hspace{-2em}$\bullet$ HCI} % HCI
    )
    -[::+45, 3] 
    -[@{closing,0.25}:+15]                      % Right closing bracket
  }
  % Now, we can put everything inside the brackets and have n as our indice.
  \polymerdelim[height=30pt, delimiters={[]}, indice=n]{opening}{closing}
\end{document}
M. Al Jumaily
  • 4,035
  • 2
  • 11
  • 26