code: @Override
     public void endContainer(CONTAINER_ELEMENT container, int depth, Deque stack) throws DocumentException {
        Class toEnd = container.getiTextClass();
        int curDepth = 0;
        Object toRemove;
        while ((toRemove = stack.peek()) != null) {
           stack.remove();
           if (toEnd.isAssignableFrom(toRemove.getClass())
               || (container == CONTAINER_ELEMENT.NESTED_TABLE && toRemove instanceof ToBeAdded)) {
              curDepth++;
           }
           if (toRemove instanceof SimpleColumns) {
              if (!stack.isEmpty()) {
                 getDocument().add((Element) stack.getLast());
                 stack.clear();
              }
  
              ((SimpleColumns) toRemove).write();
           } else if (toRemove instanceof ToBeAdded) {
              ToBeAdded ta = (ToBeAdded) toRemove;
              try {
                 addToContainer(ta.parentTable, ta.cellWithTable);
              } catch (VectorPrintException ex) {
                 throw new VectorPrintRuntimeException(ex);
              }
           } else if (stack.isEmpty()) {
              getDocument().add((Element) toRemove);
           }
           if (curDepth == depth) {
              break;
           }
        }
     }
docs: removes containers from the stack upto and including the n-th container of the given dataType. When the container
  to end is a {@link SimpleColumns} or it is the last on the stack it is added to the document.
  
  @param container
  @param depth
  @param stack
  @throws DocumentException